mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 17:35:54 +08:00
发布v1.1版本
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.iot.domain.AlertLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备告警Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
public interface IAlertLogService
|
||||
{
|
||||
/**
|
||||
* 查询设备告警
|
||||
*
|
||||
* @param alertLogId 设备告警主键
|
||||
* @return 设备告警
|
||||
*/
|
||||
public AlertLog selectAlertLogByAlertLogId(Long alertLogId);
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*
|
||||
* @param alertLog 设备告警
|
||||
* @return 设备告警集合
|
||||
*/
|
||||
public List<AlertLog> selectAlertLogList(AlertLog alertLog);
|
||||
|
||||
/**
|
||||
* 新增设备告警
|
||||
*
|
||||
* @param alertLog 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertAlertLog(AlertLog alertLog);
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*
|
||||
* @param alertLog 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateAlertLog(AlertLog alertLog);
|
||||
|
||||
/**
|
||||
* 批量删除设备告警
|
||||
*
|
||||
* @param alertLogIds 需要删除的设备告警主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAlertLogByAlertLogIds(Long[] alertLogIds);
|
||||
|
||||
/**
|
||||
* 删除设备告警信息
|
||||
*
|
||||
* @param alertLogId 设备告警主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAlertLogByAlertLogId(Long alertLogId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.Alert;
|
||||
|
||||
/**
|
||||
* 设备告警Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
public interface IAlertService
|
||||
{
|
||||
/**
|
||||
* 查询设备告警
|
||||
*
|
||||
* @param alertId 设备告警主键
|
||||
* @return 设备告警
|
||||
*/
|
||||
public Alert selectAlertByAlertId(Long alertId);
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*
|
||||
* @param alert 设备告警
|
||||
* @return 设备告警集合
|
||||
*/
|
||||
public List<Alert> selectAlertList(Alert alert);
|
||||
|
||||
/**
|
||||
* 新增设备告警
|
||||
*
|
||||
* @param alert 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertAlert(Alert alert);
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*
|
||||
* @param alert 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateAlert(Alert alert);
|
||||
|
||||
/**
|
||||
* 批量删除设备告警
|
||||
*
|
||||
* @param alertIds 需要删除的设备告警主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAlertByAlertIds(Long[] alertIds);
|
||||
|
||||
/**
|
||||
* 删除设备告警信息
|
||||
*
|
||||
* @param alertId 设备告警主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAlertByAlertId(Long alertId);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.iot.domain.Category;
|
||||
import com.ruoyi.iot.model.IdAndName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品分类Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface ICategoryService
|
||||
{
|
||||
/**
|
||||
* 查询产品分类
|
||||
*
|
||||
* @param categoryId 产品分类主键
|
||||
* @return 产品分类
|
||||
*/
|
||||
public Category selectCategoryByCategoryId(Long categoryId);
|
||||
|
||||
/**
|
||||
* 查询产品分类列表
|
||||
*
|
||||
* @param category 产品分类
|
||||
* @return 产品分类集合
|
||||
*/
|
||||
public List<Category> selectCategoryList(Category category);
|
||||
|
||||
/**
|
||||
* 查询产品简短分类列表
|
||||
*
|
||||
* @return 产品分类集合
|
||||
*/
|
||||
public List<IdAndName> selectCategoryShortList();
|
||||
|
||||
/**
|
||||
* 新增产品分类
|
||||
*
|
||||
* @param category 产品分类
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertCategory(Category category);
|
||||
|
||||
/**
|
||||
* 修改产品分类
|
||||
*
|
||||
* @param category 产品分类
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCategory(Category category);
|
||||
|
||||
/**
|
||||
* 批量删除产品分类
|
||||
*
|
||||
* @param categoryIds 需要删除的产品分类主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public AjaxResult deleteCategoryByCategoryIds(Long[] categoryIds);
|
||||
|
||||
/**
|
||||
* 删除产品分类信息
|
||||
*
|
||||
* @param categoryId 产品分类主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteCategoryByCategoryId(Long categoryId);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.common.exception.job.TaskException;
|
||||
import com.ruoyi.iot.domain.DeviceJob;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务调度信息信息 服务层
|
||||
*
|
||||
* @author kerwincui
|
||||
*/
|
||||
public interface IDeviceJobService
|
||||
{
|
||||
/**
|
||||
* 获取quartz调度器的计划任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 调度任务集合
|
||||
*/
|
||||
public List<DeviceJob> selectJobList(DeviceJob job);
|
||||
|
||||
/**
|
||||
* 通过调度任务ID查询调度信息
|
||||
*
|
||||
* @param jobId 调度任务ID
|
||||
* @return 调度任务对象信息
|
||||
*/
|
||||
public DeviceJob selectJobById(Long jobId);
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int pauseJob(DeviceJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 恢复任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int resumeJob(DeviceJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 删除任务后,所对应的trigger也将被删除
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJob(DeviceJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 批量删除调度信息
|
||||
*
|
||||
* @param jobIds 需要删除的任务ID
|
||||
* @return 结果
|
||||
*/
|
||||
public void deleteJobByIds(Long[] jobIds) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 根据设备Ids批量删除调度信息
|
||||
*
|
||||
* @param deviceIds 需要删除数据的设备Ids
|
||||
* @return 结果
|
||||
*/
|
||||
public void deleteJobByDeviceIds(Long[] deviceIds) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 任务调度状态修改
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int changeStatus(DeviceJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 立即运行任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public void run(DeviceJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 新增任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertJob(DeviceJob job) throws SchedulerException, TaskException;
|
||||
|
||||
/**
|
||||
* 更新任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateJob(DeviceJob job) throws SchedulerException, TaskException;
|
||||
|
||||
/**
|
||||
* 校验cron表达式是否有效
|
||||
*
|
||||
* @param cronExpression 表达式
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean checkCronExpressionIsValid(String cronExpression);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.model.MonitorModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备日志Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
public interface IDeviceLogService
|
||||
{
|
||||
/**
|
||||
* 查询设备日志
|
||||
*
|
||||
* @param logId 设备日志主键
|
||||
* @return 设备日志
|
||||
*/
|
||||
public DeviceLog selectDeviceLogByLogId(Long logId);
|
||||
|
||||
/**
|
||||
* 查询设备日志列表
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 设备日志集合
|
||||
*/
|
||||
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
|
||||
|
||||
/**
|
||||
* 查询设备监测数据
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 设备日志集合
|
||||
*/
|
||||
public List<MonitorModel> selectMonitorList(DeviceLog deviceLog);
|
||||
|
||||
/**
|
||||
* 新增设备日志
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceLog(DeviceLog deviceLog);
|
||||
|
||||
/**
|
||||
* 修改设备日志
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDeviceLog(DeviceLog deviceLog);
|
||||
|
||||
/**
|
||||
* 批量删除设备日志
|
||||
*
|
||||
* @param logIds 需要删除的设备日志主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceLogByLogIds(Long[] logIds);
|
||||
|
||||
/**
|
||||
* 删除设备日志信息
|
||||
*
|
||||
* @param logId 设备日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceLogByLogId(Long logId);
|
||||
|
||||
/**
|
||||
* 根据设备IDs批量删除设备日志
|
||||
*
|
||||
* @param deviceIds 需要删除的设备日志IDs
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceLogByDeviceIds(Long[] deviceIds);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.model.*;
|
||||
import com.ruoyi.iot.model.ThingsModels.ThingsModelShadow;
|
||||
import com.ruoyi.iot.model.ThingsModels.ThingsModelValuesInput;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IDeviceService
|
||||
{
|
||||
/**
|
||||
* 查询设备
|
||||
*
|
||||
* @param deviceId 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
public Device selectDeviceByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备
|
||||
*
|
||||
* @param serialNumber 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
public Device selectDeviceBySerialNumber(String serialNumber);
|
||||
|
||||
/**
|
||||
* 根据设备编号查询简介设备
|
||||
*
|
||||
* @param serialNumber 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
public Device selectShortDeviceBySerialNumber(String serialNumber);
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备认证信息
|
||||
*
|
||||
* @param model 设备编号和产品ID
|
||||
* @return 设备
|
||||
*/
|
||||
public DeviceAuthenticateModel selectDeviceAuthenticate(AuthenticateInputModel model);
|
||||
|
||||
/**
|
||||
* 查询设备和运行状态
|
||||
*
|
||||
* @param deviceId 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
public DeviceShortOutput selectDeviceRunningStatusByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 上报设备的物模型
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public int reportDeviceThingsModelValue(ThingsModelValuesInput input,int type,boolean isShadow);
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 设备集合
|
||||
*/
|
||||
public List<Device> selectDeviceList(Device device);
|
||||
|
||||
/**
|
||||
* 查询所有设备简短列表
|
||||
*
|
||||
* @return 设备
|
||||
*/
|
||||
public List<DeviceAllShortOutput> selectAllDeviceShortList();
|
||||
|
||||
/**
|
||||
* 查询设备简短列表
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 设备集合
|
||||
*/
|
||||
public List<DeviceShortOutput> selectDeviceShortList(Device device);
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
public Device insertDevice(Device device);
|
||||
|
||||
/**
|
||||
* 设备认证后自动添加设备
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceAuto(String serialNumber,Long userId,Long productId);
|
||||
|
||||
/**
|
||||
* 获取设备设置的影子
|
||||
* @param device
|
||||
* @return
|
||||
*/
|
||||
public ThingsModelShadow getDeviceShadowThingsModel(Device device);
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDevice(Device device);
|
||||
|
||||
/**
|
||||
* 更新设备状态
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDeviceStatusAndLocation(Device device,String ipAddress);
|
||||
|
||||
/**
|
||||
* 上报设备信息
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int reportDevice(Device device);
|
||||
|
||||
/**
|
||||
* 批量删除设备
|
||||
*
|
||||
* @param deviceIds 需要删除的设备主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceByDeviceIds(Long[] deviceIds) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 删除设备信息
|
||||
*
|
||||
* @param deviceId 设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 生成设备唯一编号
|
||||
* @return 结果
|
||||
*/
|
||||
public String generationDeviceNum();
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.DeviceUser;
|
||||
|
||||
/**
|
||||
* 设备用户Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IDeviceUserService
|
||||
{
|
||||
/**
|
||||
* 查询设备用户
|
||||
*
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 设备用户
|
||||
*/
|
||||
public DeviceUser selectDeviceUserByDeviceId(Long deviceId);
|
||||
|
||||
/**
|
||||
* 查询设备用户列表
|
||||
*
|
||||
* @param deviceUser 设备用户
|
||||
* @return 设备用户集合
|
||||
*/
|
||||
public List<DeviceUser> selectDeviceUserList(DeviceUser deviceUser);
|
||||
|
||||
/**
|
||||
* 新增设备用户
|
||||
*
|
||||
* @param deviceUser 设备用户
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDeviceUser(DeviceUser deviceUser);
|
||||
|
||||
/**
|
||||
* 修改设备用户
|
||||
*
|
||||
* @param deviceUser 设备用户
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDeviceUser(DeviceUser deviceUser);
|
||||
|
||||
/**
|
||||
* 批量删除设备用户
|
||||
*
|
||||
* @param deviceIds 需要删除的设备用户主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceUserByDeviceIds(Long[] deviceIds);
|
||||
|
||||
/**
|
||||
* 删除设备用户信息
|
||||
*
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeviceUserByDeviceId(Long deviceId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.Firmware;
|
||||
|
||||
/**
|
||||
* 产品固件Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IFirmwareService
|
||||
{
|
||||
/**
|
||||
* 查询产品固件
|
||||
*
|
||||
* @param firmwareId 产品固件主键
|
||||
* @return 产品固件
|
||||
*/
|
||||
public Firmware selectFirmwareByFirmwareId(Long firmwareId);
|
||||
|
||||
/**
|
||||
* 查询产品固件列表
|
||||
*
|
||||
* @param firmware 产品固件
|
||||
* @return 产品固件集合
|
||||
*/
|
||||
public List<Firmware> selectFirmwareList(Firmware firmware);
|
||||
|
||||
/**
|
||||
* 新增产品固件
|
||||
*
|
||||
* @param firmware 产品固件
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertFirmware(Firmware firmware);
|
||||
|
||||
/**
|
||||
* 修改产品固件
|
||||
*
|
||||
* @param firmware 产品固件
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateFirmware(Firmware firmware);
|
||||
|
||||
/**
|
||||
* 批量删除产品固件
|
||||
*
|
||||
* @param firmwareIds 需要删除的产品固件主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteFirmwareByFirmwareIds(Long[] firmwareIds);
|
||||
|
||||
/**
|
||||
* 删除产品固件信息
|
||||
*
|
||||
* @param firmwareId 产品固件主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteFirmwareByFirmwareId(Long firmwareId);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.iot.domain.Group;
|
||||
import com.ruoyi.iot.model.DeviceGroupInput;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备分组Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IGroupService
|
||||
{
|
||||
/**
|
||||
* 查询设备分组
|
||||
*
|
||||
* @param groupId 设备分组主键
|
||||
* @return 设备分组
|
||||
*/
|
||||
public Group selectGroupByGroupId(Long groupId);
|
||||
|
||||
/**
|
||||
* 通过分组ID查询关联的设备ID数组
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
public Long[] selectDeviceIdsByGroupId(Long groupId);
|
||||
|
||||
/**
|
||||
* 查询设备分组列表
|
||||
*
|
||||
* @param group 设备分组
|
||||
* @return 设备分组集合
|
||||
*/
|
||||
public List<Group> selectGroupList(Group group);
|
||||
|
||||
/**
|
||||
* 新增设备分组
|
||||
*
|
||||
* @param group 设备分组
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGroup(Group group);
|
||||
|
||||
/**
|
||||
* 分组下批量添加设备分组
|
||||
* @return
|
||||
*/
|
||||
public int updateDeviceGroups(DeviceGroupInput input);
|
||||
|
||||
/**
|
||||
* 修改设备分组
|
||||
*
|
||||
* @param group 设备分组
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGroup(Group group);
|
||||
|
||||
/**
|
||||
* 批量删除分组
|
||||
*
|
||||
* @param groupIds 需要删除的设备分组主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGroupByGroupIds(Long[] groupIds);
|
||||
|
||||
/**
|
||||
* 删除分组信息
|
||||
*
|
||||
* @param groupId 设备分组主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGroupByGroupId(Long groupId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.OauthClientDetails;
|
||||
|
||||
/**
|
||||
* 云云对接Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-02-07
|
||||
*/
|
||||
public interface IOauthClientDetailsService
|
||||
{
|
||||
/**
|
||||
* 查询云云对接
|
||||
*
|
||||
* @param clientId 云云对接主键
|
||||
* @return 云云对接
|
||||
*/
|
||||
public OauthClientDetails selectOauthClientDetailsByClientId(String clientId);
|
||||
|
||||
/**
|
||||
* 查询云云对接列表
|
||||
*
|
||||
* @param oauthClientDetails 云云对接
|
||||
* @return 云云对接集合
|
||||
*/
|
||||
public List<OauthClientDetails> selectOauthClientDetailsList(OauthClientDetails oauthClientDetails);
|
||||
|
||||
/**
|
||||
* 新增云云对接
|
||||
*
|
||||
* @param oauthClientDetails 云云对接
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertOauthClientDetails(OauthClientDetails oauthClientDetails);
|
||||
|
||||
/**
|
||||
* 修改云云对接
|
||||
*
|
||||
* @param oauthClientDetails 云云对接
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateOauthClientDetails(OauthClientDetails oauthClientDetails);
|
||||
|
||||
/**
|
||||
* 批量删除云云对接
|
||||
*
|
||||
* @param clientIds 需要删除的云云对接主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteOauthClientDetailsByClientIds(String[] clientIds);
|
||||
|
||||
/**
|
||||
* 删除云云对接信息
|
||||
*
|
||||
* @param clientId 云云对接主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteOauthClientDetailsByClientId(String clientId);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.iot.domain.Product;
|
||||
import com.ruoyi.iot.model.ChangeProductStatusModel;
|
||||
import com.ruoyi.iot.model.IdAndName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IProductService
|
||||
{
|
||||
/**
|
||||
* 查询产品
|
||||
*
|
||||
* @param productId 产品主键
|
||||
* @return 产品
|
||||
*/
|
||||
public Product selectProductByProductId(Long productId);
|
||||
|
||||
/**
|
||||
* 查询产品列表
|
||||
*
|
||||
* @param product 产品
|
||||
* @return 产品集合
|
||||
*/
|
||||
public List<Product> selectProductList(Product product);
|
||||
|
||||
/**
|
||||
* 查询产品简短列表
|
||||
*
|
||||
* @return 产品集合
|
||||
*/
|
||||
public List<IdAndName> selectProductShortList();
|
||||
|
||||
/**
|
||||
* 新增产品
|
||||
*
|
||||
* @param product 产品
|
||||
* @return 结果
|
||||
*/
|
||||
public Product insertProduct(Product product);
|
||||
|
||||
/**
|
||||
* 修改产品
|
||||
*
|
||||
* @param product 产品
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateProduct(Product product);
|
||||
|
||||
/**
|
||||
* 更新产品状态,1-未发布,2-已发布
|
||||
*
|
||||
* @param model
|
||||
* @return 结果
|
||||
*/
|
||||
public AjaxResult changeProductStatus(ChangeProductStatusModel model);
|
||||
|
||||
/**
|
||||
* 批量删除产品
|
||||
*
|
||||
* @param productIds 需要删除的产品主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public AjaxResult deleteProductByProductIds(Long[] productIds);
|
||||
|
||||
/**
|
||||
* 删除产品信息
|
||||
*
|
||||
* @param productId 产品主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductByProductId(Long productId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.Scene;
|
||||
|
||||
/**
|
||||
* 场景联动Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
public interface ISceneService
|
||||
{
|
||||
/**
|
||||
* 查询场景联动
|
||||
*
|
||||
* @param sceneId 场景联动主键
|
||||
* @return 场景联动
|
||||
*/
|
||||
public Scene selectSceneBySceneId(Long sceneId);
|
||||
|
||||
/**
|
||||
* 查询场景联动列表
|
||||
*
|
||||
* @param scene 场景联动
|
||||
* @return 场景联动集合
|
||||
*/
|
||||
public List<Scene> selectSceneList(Scene scene);
|
||||
|
||||
/**
|
||||
* 新增场景联动
|
||||
*
|
||||
* @param scene 场景联动
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertScene(Scene scene);
|
||||
|
||||
/**
|
||||
* 修改场景联动
|
||||
*
|
||||
* @param scene 场景联动
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateScene(Scene scene);
|
||||
|
||||
/**
|
||||
* 批量删除场景联动
|
||||
*
|
||||
* @param sceneIds 需要删除的场景联动主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSceneBySceneIds(Long[] sceneIds);
|
||||
|
||||
/**
|
||||
* 删除场景联动信息
|
||||
*
|
||||
* @param sceneId 场景联动主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSceneBySceneId(Long sceneId);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.ThingsModel;
|
||||
import com.ruoyi.iot.model.ImportThingsModelInput;
|
||||
|
||||
/**
|
||||
* 物模型Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IThingsModelService
|
||||
{
|
||||
/**
|
||||
* 查询物模型
|
||||
*
|
||||
* @param modelId 物模型主键
|
||||
* @return 物模型
|
||||
*/
|
||||
public ThingsModel selectThingsModelByModelId(Long modelId);
|
||||
|
||||
/**
|
||||
* 查询物模型列表
|
||||
*
|
||||
* @param thingsModel 物模型
|
||||
* @return 物模型集合
|
||||
*/
|
||||
public List<ThingsModel> selectThingsModelList(ThingsModel thingsModel);
|
||||
|
||||
/**
|
||||
* 新增物模型
|
||||
*
|
||||
* @param thingsModel 物模型
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertThingsModel(ThingsModel thingsModel);
|
||||
|
||||
/**
|
||||
* 从模板导入物模型
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public int importByTemplateIds(ImportThingsModelInput input);
|
||||
|
||||
/**
|
||||
* 修改物模型
|
||||
*
|
||||
* @param thingsModel 物模型
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateThingsModel(ThingsModel thingsModel);
|
||||
|
||||
/**
|
||||
* 批量删除物模型
|
||||
*
|
||||
* @param modelIds 需要删除的物模型主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteThingsModelByModelIds(Long[] modelIds);
|
||||
|
||||
/**
|
||||
* 删除物模型信息
|
||||
*
|
||||
* @param modelId 物模型主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteThingsModelByModelId(Long modelId);
|
||||
|
||||
/**
|
||||
* 根据产品ID获取JSON物模型
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
public String getCacheThingsModelByProductId(Long productId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.ThingsModelTemplate;
|
||||
|
||||
/**
|
||||
* 通用物模型Service接口
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IThingsModelTemplateService
|
||||
{
|
||||
/**
|
||||
* 查询通用物模型
|
||||
*
|
||||
* @param templateId 通用物模型主键
|
||||
* @return 通用物模型
|
||||
*/
|
||||
public ThingsModelTemplate selectThingsModelTemplateByTemplateId(Long templateId);
|
||||
|
||||
/**
|
||||
* 查询通用物模型列表
|
||||
*
|
||||
* @param thingsModelTemplate 通用物模型
|
||||
* @return 通用物模型集合
|
||||
*/
|
||||
public List<ThingsModelTemplate> selectThingsModelTemplateList(ThingsModelTemplate thingsModelTemplate);
|
||||
|
||||
/**
|
||||
* 新增通用物模型
|
||||
*
|
||||
* @param thingsModelTemplate 通用物模型
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertThingsModelTemplate(ThingsModelTemplate thingsModelTemplate);
|
||||
|
||||
/**
|
||||
* 修改通用物模型
|
||||
*
|
||||
* @param thingsModelTemplate 通用物模型
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateThingsModelTemplate(ThingsModelTemplate thingsModelTemplate);
|
||||
|
||||
/**
|
||||
* 批量删除通用物模型
|
||||
*
|
||||
* @param templateIds 需要删除的通用物模型主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteThingsModelTemplateByTemplateIds(Long[] templateIds);
|
||||
|
||||
/**
|
||||
* 删除通用物模型信息
|
||||
*
|
||||
* @param templateId 通用物模型主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteThingsModelTemplateByTemplateId(Long templateId);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import com.ruoyi.iot.model.RegisterUserInput;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public interface IToolService
|
||||
{
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public String register(RegisterUserInput registerBody);
|
||||
|
||||
/**
|
||||
* 生成随机数字和字母
|
||||
*/
|
||||
public String getStringRandom(int length);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.AlertLogMapper;
|
||||
import com.ruoyi.iot.domain.AlertLog;
|
||||
import com.ruoyi.iot.service.IAlertLogService;
|
||||
|
||||
/**
|
||||
* 设备告警Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Service
|
||||
public class AlertLogServiceImpl implements IAlertLogService
|
||||
{
|
||||
@Autowired
|
||||
private AlertLogMapper alertLogMapper;
|
||||
|
||||
/**
|
||||
* 查询设备告警
|
||||
*
|
||||
* @param alertLogId 设备告警主键
|
||||
* @return 设备告警
|
||||
*/
|
||||
@Override
|
||||
public AlertLog selectAlertLogByAlertLogId(Long alertLogId)
|
||||
{
|
||||
return alertLogMapper.selectAlertLogByAlertLogId(alertLogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*
|
||||
* @param alertLog 设备告警
|
||||
* @return 设备告警
|
||||
*/
|
||||
@Override
|
||||
public List<AlertLog> selectAlertLogList(AlertLog alertLog)
|
||||
{
|
||||
return alertLogMapper.selectAlertLogList(alertLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备告警
|
||||
*
|
||||
* @param alertLog 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertAlertLog(AlertLog alertLog)
|
||||
{
|
||||
alertLog.setCreateTime(DateUtils.getNowDate());
|
||||
return alertLogMapper.insertAlertLog(alertLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*
|
||||
* @param alertLog 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateAlertLog(AlertLog alertLog)
|
||||
{
|
||||
alertLog.setUpdateTime(DateUtils.getNowDate());
|
||||
return alertLogMapper.updateAlertLog(alertLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除设备告警
|
||||
*
|
||||
* @param alertLogIds 需要删除的设备告警主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAlertLogByAlertLogIds(Long[] alertLogIds)
|
||||
{
|
||||
return alertLogMapper.deleteAlertLogByAlertLogIds(alertLogIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备告警信息
|
||||
*
|
||||
* @param alertLogId 设备告警主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAlertLogByAlertLogId(Long alertLogId)
|
||||
{
|
||||
return alertLogMapper.deleteAlertLogByAlertLogId(alertLogId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.AlertMapper;
|
||||
import com.ruoyi.iot.domain.Alert;
|
||||
import com.ruoyi.iot.service.IAlertService;
|
||||
|
||||
/**
|
||||
* 设备告警Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Service
|
||||
public class AlertServiceImpl implements IAlertService
|
||||
{
|
||||
@Autowired
|
||||
private AlertMapper alertMapper;
|
||||
|
||||
/**
|
||||
* 查询设备告警
|
||||
*
|
||||
* @param alertId 设备告警主键
|
||||
* @return 设备告警
|
||||
*/
|
||||
@Override
|
||||
public Alert selectAlertByAlertId(Long alertId)
|
||||
{
|
||||
return alertMapper.selectAlertByAlertId(alertId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*
|
||||
* @param alert 设备告警
|
||||
* @return 设备告警
|
||||
*/
|
||||
@Override
|
||||
public List<Alert> selectAlertList(Alert alert)
|
||||
{
|
||||
return alertMapper.selectAlertList(alert);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备告警
|
||||
*
|
||||
* @param alert 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertAlert(Alert alert)
|
||||
{
|
||||
alert.setCreateTime(DateUtils.getNowDate());
|
||||
return alertMapper.insertAlert(alert);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*
|
||||
* @param alert 设备告警
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateAlert(Alert alert)
|
||||
{
|
||||
alert.setUpdateTime(DateUtils.getNowDate());
|
||||
return alertMapper.updateAlert(alert);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除设备告警
|
||||
*
|
||||
* @param alertIds 需要删除的设备告警主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAlertByAlertIds(Long[] alertIds)
|
||||
{
|
||||
return alertMapper.deleteAlertByAlertIds(alertIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备告警信息
|
||||
*
|
||||
* @param alertId 设备告警主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAlertByAlertId(Long alertId)
|
||||
{
|
||||
return alertMapper.deleteAlertByAlertId(alertId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.Category;
|
||||
import com.ruoyi.iot.mapper.CategoryMapper;
|
||||
import com.ruoyi.iot.model.IdAndName;
|
||||
import com.ruoyi.iot.service.ICategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 产品分类Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class CategoryServiceImpl implements ICategoryService
|
||||
{
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
/**
|
||||
* 查询产品分类
|
||||
*
|
||||
* @param categoryId 产品分类主键
|
||||
* @return 产品分类
|
||||
*/
|
||||
@Override
|
||||
public Category selectCategoryByCategoryId(Long categoryId)
|
||||
{
|
||||
return categoryMapper.selectCategoryByCategoryId(categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品分类列表
|
||||
*
|
||||
* @param category 产品分类
|
||||
* @return 产品分类
|
||||
*/
|
||||
@Override
|
||||
public List<Category> selectCategoryList(Category category)
|
||||
{
|
||||
return categoryMapper.selectCategoryList(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品分简短类列表
|
||||
*
|
||||
* @return 产品分类
|
||||
*/
|
||||
@Override
|
||||
public List<IdAndName> selectCategoryShortList()
|
||||
{
|
||||
return categoryMapper.selectCategoryShortList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品分类
|
||||
*
|
||||
* @param category 产品分类
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertCategory(Category category)
|
||||
{
|
||||
SysUser user = getLoginUser().getUser();
|
||||
List<SysRole> roles=user.getRoles();
|
||||
if(roles==null || roles.size()==0) {return 0;}
|
||||
// 系统管理员
|
||||
if(roles.stream().anyMatch(a->a.getRoleKey().equals("admin"))){
|
||||
category.setIsSys(1);
|
||||
}
|
||||
category.setTenantId(user.getUserId());
|
||||
category.setTenantName(user.getUserName());
|
||||
category.setCreateTime(DateUtils.getNowDate());
|
||||
return categoryMapper.insertCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品分类
|
||||
*
|
||||
* @param category 产品分类
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCategory(Category category)
|
||||
{
|
||||
category.setUpdateTime(DateUtils.getNowDate());
|
||||
return categoryMapper.updateCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除产品分类
|
||||
*
|
||||
* @param categoryIds 需要删除的产品分类主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult deleteCategoryByCategoryIds(Long[] categoryIds)
|
||||
{
|
||||
int productCount=categoryMapper.productCountInCategorys(categoryIds);
|
||||
if(productCount>0){
|
||||
return AjaxResult.error("删除失败,请先删除对应分类下的产品");
|
||||
}
|
||||
if(categoryMapper.deleteCategoryByCategoryIds(categoryIds)>0){
|
||||
return AjaxResult.success("删除成功");
|
||||
}
|
||||
return AjaxResult.error("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品分类信息
|
||||
*
|
||||
* @param categoryId 产品分类主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteCategoryByCategoryId(Long categoryId)
|
||||
{
|
||||
return categoryMapper.deleteCategoryByCategoryId(categoryId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.ScheduleConstants;
|
||||
import com.ruoyi.common.exception.job.TaskException;
|
||||
import com.ruoyi.iot.domain.DeviceJob;
|
||||
import com.ruoyi.iot.mapper.DeviceJobMapper;
|
||||
import com.ruoyi.iot.service.IDeviceJobService;
|
||||
import com.ruoyi.iot.util.quartz.CronUtils;
|
||||
import com.ruoyi.iot.util.quartz.ScheduleUtils;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务调度信息 服务层
|
||||
*
|
||||
* @author kerwincui
|
||||
*/
|
||||
@Service
|
||||
public class DeviceJobServiceImpl implements IDeviceJobService
|
||||
{
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Autowired
|
||||
private DeviceJobMapper jobMapper;
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() throws SchedulerException, TaskException
|
||||
{
|
||||
scheduler.clear();
|
||||
List<DeviceJob> jobList = jobMapper.selectJobAll();
|
||||
for (DeviceJob deviceJob : jobList)
|
||||
{
|
||||
ScheduleUtils.createScheduleJob(scheduler, deviceJob);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取quartz调度器的计划任务列表
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceJob> selectJobList(DeviceJob job)
|
||||
{
|
||||
return jobMapper.selectJobList(job);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过调度任务ID查询调度信息
|
||||
*
|
||||
* @param jobId 调度任务ID
|
||||
* @return 调度任务对象信息
|
||||
*/
|
||||
@Override
|
||||
public DeviceJob selectJobById(Long jobId)
|
||||
{
|
||||
return jobMapper.selectJobById(jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int pauseJob(DeviceJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
||||
int rows = jobMapper.updateJob(job);
|
||||
if (rows > 0)
|
||||
{
|
||||
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int resumeJob(DeviceJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
|
||||
int rows = jobMapper.updateJob(job);
|
||||
if (rows > 0)
|
||||
{
|
||||
scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务后,所对应的trigger也将被删除
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteJob(DeviceJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
int rows = jobMapper.deleteJobById(jobId);
|
||||
if (rows > 0)
|
||||
{
|
||||
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除调度信息
|
||||
*
|
||||
* @param jobIds 需要删除的任务ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobByIds(Long[] jobIds) throws SchedulerException
|
||||
{
|
||||
for (Long jobId : jobIds)
|
||||
{
|
||||
DeviceJob job = jobMapper.selectJobById(jobId);
|
||||
deleteJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备Ids批量删除调度信息
|
||||
*
|
||||
* @param deviceIds 需要删除数据的设备Ids
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobByDeviceIds(Long[] deviceIds) throws SchedulerException
|
||||
{
|
||||
// 查出所有job
|
||||
List<DeviceJob> deviceJobs=jobMapper.selectShortJobListByDeviceIds(deviceIds);
|
||||
|
||||
// 批量删除job
|
||||
int rows=jobMapper.deleteJobByDeviceIds(deviceIds);
|
||||
|
||||
// 批量删除调度器
|
||||
for(DeviceJob job:deviceJobs){
|
||||
scheduler.deleteJob(ScheduleUtils.getJobKey(job.getJobId(), job.getJobGroup()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务调度状态修改
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int changeStatus(DeviceJob job) throws SchedulerException
|
||||
{
|
||||
int rows = 0;
|
||||
String status = job.getStatus();
|
||||
if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
|
||||
{
|
||||
rows = resumeJob(job);
|
||||
}
|
||||
else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
|
||||
{
|
||||
rows = pauseJob(job);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即运行任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void run(DeviceJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
DeviceJob properties = selectJobById(job.getJobId());
|
||||
// 参数
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
|
||||
scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增任务
|
||||
*
|
||||
* @param deviceJob 调度信息 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertJob(DeviceJob deviceJob) throws SchedulerException, TaskException
|
||||
{
|
||||
int rows = jobMapper.insertJob(deviceJob);
|
||||
if (rows > 0)
|
||||
{
|
||||
ScheduleUtils.createScheduleJob(scheduler, deviceJob);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务的时间表达式
|
||||
*
|
||||
* @param deviceJob 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateJob(DeviceJob deviceJob) throws SchedulerException, TaskException
|
||||
{
|
||||
DeviceJob properties = selectJobById(deviceJob.getJobId());
|
||||
int rows = jobMapper.updateJob(deviceJob);
|
||||
if (rows > 0)
|
||||
{
|
||||
updateSchedulerJob(deviceJob, properties.getJobGroup());
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务
|
||||
*
|
||||
* @param deviceJob 任务对象
|
||||
* @param jobGroup 任务组名
|
||||
*/
|
||||
public void updateSchedulerJob(DeviceJob deviceJob, String jobGroup) throws SchedulerException, TaskException
|
||||
{
|
||||
Long jobId = deviceJob.getJobId();
|
||||
// 判断是否存在
|
||||
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
||||
if (scheduler.checkExists(jobKey))
|
||||
{
|
||||
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
||||
scheduler.deleteJob(jobKey);
|
||||
}
|
||||
ScheduleUtils.createScheduleJob(scheduler, deviceJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验cron表达式是否有效
|
||||
*
|
||||
* @param cronExpression 表达式
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkCronExpressionIsValid(String cronExpression)
|
||||
{
|
||||
return CronUtils.isValid(cronExpression);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.mapper.DeviceLogMapper;
|
||||
import com.ruoyi.iot.model.MonitorModel;
|
||||
import com.ruoyi.iot.service.IDeviceLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备日志Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Service
|
||||
public class DeviceLogServiceImpl implements IDeviceLogService
|
||||
{
|
||||
@Autowired
|
||||
private DeviceLogMapper deviceLogMapper;
|
||||
|
||||
/**
|
||||
* 查询设备日志
|
||||
*
|
||||
* @param logId 设备日志主键
|
||||
* @return 设备日志
|
||||
*/
|
||||
@Override
|
||||
public DeviceLog selectDeviceLogByLogId(Long logId)
|
||||
{
|
||||
return deviceLogMapper.selectDeviceLogByLogId(logId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备日志列表
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 设备日志
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog)
|
||||
{
|
||||
return deviceLogMapper.selectDeviceLogList(deviceLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备监测数据
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 设备日志
|
||||
*/
|
||||
@Override
|
||||
public List<MonitorModel> selectMonitorList(DeviceLog deviceLog)
|
||||
{
|
||||
return deviceLogMapper.selectMonitorList(deviceLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备日志
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDeviceLog(DeviceLog deviceLog)
|
||||
{
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
return deviceLogMapper.insertDeviceLog(deviceLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备日志
|
||||
*
|
||||
* @param deviceLog 设备日志
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDeviceLog(DeviceLog deviceLog)
|
||||
{
|
||||
return deviceLogMapper.updateDeviceLog(deviceLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除设备日志
|
||||
*
|
||||
* @param logIds 需要删除的设备日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceLogByLogIds(Long[] logIds)
|
||||
{
|
||||
return deviceLogMapper.deleteDeviceLogByLogIds(logIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备Ids批量删除设备日志
|
||||
*
|
||||
* @param deviceIds 需要删除数据的设备Ids
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceLogByDeviceIds(Long[] deviceIds)
|
||||
{
|
||||
return deviceLogMapper.deleteDeviceLogByDeviceIds(deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备日志信息
|
||||
*
|
||||
* @param logId 设备日志主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceLogByLogId(Long logId)
|
||||
{
|
||||
return deviceLogMapper.deleteDeviceLogByLogId(logId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,674 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.common.utils.ip.IpUtils;
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.DeviceLog;
|
||||
import com.ruoyi.iot.domain.Product;
|
||||
import com.ruoyi.iot.mapper.DeviceLogMapper;
|
||||
import com.ruoyi.iot.mapper.DeviceMapper;
|
||||
import com.ruoyi.iot.mapper.DeviceUserMapper;
|
||||
import com.ruoyi.iot.model.*;
|
||||
import com.ruoyi.iot.model.ThingsModelItem.*;
|
||||
import com.ruoyi.iot.model.ThingsModels.*;
|
||||
import com.ruoyi.iot.service.IDeviceLogService;
|
||||
import com.ruoyi.iot.service.IDeviceService;
|
||||
import com.ruoyi.iot.service.IProductService;
|
||||
import com.ruoyi.iot.service.IToolService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 设备Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class DeviceServiceImpl implements IDeviceService {
|
||||
private static final Logger log = LoggerFactory.getLogger(DeviceServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
@Autowired
|
||||
private DeviceUserMapper deviceUserMapper;
|
||||
|
||||
@Autowired
|
||||
private ThingsModelServiceImpl thingsModelService;
|
||||
|
||||
@Autowired
|
||||
private DeviceJobServiceImpl deviceJobService;
|
||||
|
||||
@Autowired
|
||||
private DeviceLogMapper deviceLogMapper;
|
||||
|
||||
@Autowired
|
||||
private IToolService toolService;
|
||||
|
||||
@Autowired
|
||||
private IProductService productService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceLogService deviceLogService;
|
||||
|
||||
/**
|
||||
* 查询设备
|
||||
*
|
||||
* @param deviceId 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public Device selectDeviceByDeviceId(Long deviceId) {
|
||||
return deviceMapper.selectDeviceByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备
|
||||
*
|
||||
* @param serialNumber 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public Device selectDeviceBySerialNumber(String serialNumber) {
|
||||
return deviceMapper.selectDeviceBySerialNumber(serialNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备编号查询简介设备
|
||||
*
|
||||
* @param serialNumber 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public Device selectShortDeviceBySerialNumber(String serialNumber) {
|
||||
return deviceMapper.selectShortDeviceBySerialNumber(serialNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备认证信息
|
||||
*
|
||||
* @param model 设备编号和产品ID
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public DeviceAuthenticateModel selectDeviceAuthenticate(AuthenticateInputModel model) {
|
||||
return deviceMapper.selectDeviceAuthenticate(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备
|
||||
*
|
||||
* @param deviceId 设备主键
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public DeviceShortOutput selectDeviceRunningStatusByDeviceId(Long deviceId) {
|
||||
DeviceShortOutput device = deviceMapper.selectDeviceRunningStatusByDeviceId(deviceId);
|
||||
JSONObject thingsModelObject = JSONObject.parseObject(thingsModelService.getCacheThingsModelByProductId(device.getProductId()));
|
||||
JSONArray properties = thingsModelObject.getJSONArray("properties");
|
||||
JSONArray functions = thingsModelObject.getJSONArray("functions");
|
||||
// 物模型转换为对象中的不同类别集合
|
||||
convertJsonToCategoryList(properties, device, false, false);
|
||||
convertJsonToCategoryList(functions, device, false, false);
|
||||
device.setThingsModelValue("");
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设备的物模型
|
||||
*
|
||||
* @param input 设备ID和物模型值
|
||||
* @param type 1=属性 2=功能
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int reportDeviceThingsModelValue(ThingsModelValuesInput input, int type,boolean isShadow) {
|
||||
// 查询物模型
|
||||
String thingsModels = thingsModelService.getCacheThingsModelByProductId(input.getProductId());
|
||||
JSONObject thingsModelObject = JSONObject.parseObject(thingsModels);
|
||||
List<ThingsModelValueItemDto> valueList =null;
|
||||
if(type==1){
|
||||
JSONArray properties = thingsModelObject.getJSONArray("properties");
|
||||
valueList = properties.toJavaList(ThingsModelValueItemDto.class);
|
||||
}else if(type==2){
|
||||
JSONArray functions = thingsModelObject.getJSONArray("functions");
|
||||
valueList = functions.toJavaList(ThingsModelValueItemDto.class);
|
||||
}
|
||||
|
||||
// 查询物模型值
|
||||
ThingsModelValuesOutput deviceThings = deviceMapper.selectDeviceThingsModelValueBySerialNumber(input.getDeviceNumber());
|
||||
List<ThingsModelValueItem> thingsModelValues = JSONObject.parseArray(deviceThings.getThingsModelValue(), ThingsModelValueItem.class);
|
||||
|
||||
for(int i=0;i<input.getThingsModelValueRemarkItem().size();i++){
|
||||
// 赋值
|
||||
for(int j=0;j<thingsModelValues.size();j++){
|
||||
if (input.getThingsModelValueRemarkItem().get(i).getId().equals(thingsModelValues.get(j).getId())) {
|
||||
// 影子模式只更新影子值
|
||||
if(!isShadow){
|
||||
thingsModelValues.get(j).setValue(String.valueOf(input.getThingsModelValueRemarkItem().get(i).getValue()));
|
||||
}
|
||||
thingsModelValues.get(j).setShadow(String.valueOf(input.getThingsModelValueRemarkItem().get(i).getValue()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//日志
|
||||
for(int k=0;k<valueList.size();k++){
|
||||
if (valueList.get(k).getId().equals(input.getThingsModelValueRemarkItem().get(i).getId())) {
|
||||
valueList.get(k).setValue(input.getThingsModelValueRemarkItem().get(i).getValue());
|
||||
// TODO 场景联动、告警规则匹配处理
|
||||
|
||||
// 添加到设备日志
|
||||
DeviceLog deviceLog = new DeviceLog();
|
||||
deviceLog.setDeviceId(deviceThings.getDeviceId());
|
||||
deviceLog.setSerialNumber(deviceThings.getSerialNumber());
|
||||
deviceLog.setDeviceName(deviceThings.getDeviceName());
|
||||
deviceLog.setLogValue(input.getThingsModelValueRemarkItem().get(i).getValue());
|
||||
deviceLog.setRemark(input.getThingsModelValueRemarkItem().get(i).getRemark());
|
||||
deviceLog.setIdentity(input.getThingsModelValueRemarkItem().get(i).getId());
|
||||
deviceLog.setCreateTime(DateUtils.getNowDate());
|
||||
deviceLog.setIsMonitor(valueList.get(k).getIsMonitor());
|
||||
deviceLog.setLogType(type);
|
||||
deviceLogMapper.insertDeviceLog(deviceLog);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
input.setStringValue(JSONObject.toJSONString(thingsModelValues));
|
||||
input.setDeviceId(deviceThings.getDeviceId());
|
||||
return deviceMapper.updateDeviceThingsModelValue(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public List<Device> selectDeviceList(Device device) {
|
||||
return deviceMapper.selectDeviceList(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有设备简短列表
|
||||
*
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceAllShortOutput> selectAllDeviceShortList() {
|
||||
// TODO redis缓存
|
||||
return deviceMapper.selectAllDeviceShortList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备简短列表
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 设备
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceShortOutput> selectDeviceShortList(Device device) {
|
||||
// TODO 关联设备用户表
|
||||
List<DeviceShortOutput> deviceList = deviceMapper.selectDeviceShortList(device);
|
||||
for (int i = 0; i < deviceList.size(); i++) {
|
||||
JSONObject thingsModelObject = JSONObject.parseObject(thingsModelService.getCacheThingsModelByProductId(deviceList.get(i).getProductId()));
|
||||
JSONArray properties = thingsModelObject.getJSONArray("properties");
|
||||
JSONArray functions = thingsModelObject.getJSONArray("functions");
|
||||
// 物模型转换为对象中的不同类别集合
|
||||
convertJsonToCategoryList(properties, deviceList.get(i), true, true);
|
||||
convertJsonToCategoryList(functions, deviceList.get(i), true, false);
|
||||
deviceList.get(i).setThingsModelValue("");
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Json物模型集合转换为对象中的分类集合
|
||||
*
|
||||
* @param jsonArray 物模型集合
|
||||
* @param isOnlyTop 是否只显示置顶数据
|
||||
* @param isOnlyRead 是否设置为只读
|
||||
* @param device 设备
|
||||
*/
|
||||
@Async
|
||||
public void convertJsonToCategoryList(JSONArray jsonArray, DeviceShortOutput device, boolean isOnlyTop, boolean isOnlyRead) {
|
||||
// 获取物模型值
|
||||
JSONArray thingsValueArray = JSONObject.parseArray(device.getThingsModelValue());
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject thingsJson = jsonArray.getJSONObject(i);
|
||||
JSONObject datatypeJson = thingsJson.getJSONObject("datatype");
|
||||
ThingsModelItemBase thingsModel = new ThingsModelItemBase();
|
||||
thingsModel.setIsTop(thingsJson.getInteger("isTop"));
|
||||
// 只显示isTop数据
|
||||
if (thingsModel.getIsTop() == 0 && isOnlyTop == true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
thingsModel.setId(thingsJson.getString("id"));
|
||||
thingsModel.setName(thingsJson.getString("name"));
|
||||
thingsModel.setIsMonitor(thingsJson.getInteger("isMonitor") == null ? 0 : thingsJson.getInteger("isMonitor"));
|
||||
thingsModel.setType(datatypeJson.getString("type"));
|
||||
thingsModel.setValue("");
|
||||
// 获取value
|
||||
for (int j = 0; j < thingsValueArray.size(); j++) {
|
||||
if (thingsValueArray.getJSONObject(j).getString("id").equals(thingsModel.getId())) {
|
||||
thingsModel.setValue(thingsValueArray.getJSONObject(j).getString("value"));
|
||||
thingsModel.setShadow(thingsValueArray.getJSONObject(j).getString("shadow"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 根据分类不同,存储到不同集合
|
||||
if (datatypeJson.getString("type").equals("decimal")) {
|
||||
DecimalModelOutput model = new DecimalModelOutput();
|
||||
BeanUtils.copyProperties(thingsModel, model);
|
||||
model.setMax(datatypeJson.getBigDecimal("max"));
|
||||
model.setMin(datatypeJson.getBigDecimal("min"));
|
||||
model.setStep(datatypeJson.getBigDecimal("step"));
|
||||
model.setUnit(datatypeJson.getString("unit"));
|
||||
if (model.getIsMonitor() == 1 || isOnlyRead == true) {
|
||||
ReadOnlyModelOutput readonlyModel = new ReadOnlyModelOutput();
|
||||
BeanUtils.copyProperties(model, readonlyModel);
|
||||
device.getReadOnlyList().add(readonlyModel);
|
||||
} else {
|
||||
device.getDecimalList().add(model);
|
||||
}
|
||||
} else if (datatypeJson.getString("type").equals("integer")) {
|
||||
IntegerModelOutput model = new IntegerModelOutput();
|
||||
BeanUtils.copyProperties(thingsModel, model);
|
||||
model.setMax(datatypeJson.getBigDecimal("max"));
|
||||
model.setMin(datatypeJson.getBigDecimal("min"));
|
||||
model.setStep(datatypeJson.getBigDecimal("step"));
|
||||
model.setUnit(datatypeJson.getString("unit"));
|
||||
if (model.getIsMonitor() == 1 || isOnlyRead == true) {
|
||||
ReadOnlyModelOutput readonlyModel = new ReadOnlyModelOutput();
|
||||
BeanUtils.copyProperties(model, readonlyModel);
|
||||
device.getReadOnlyList().add(readonlyModel);
|
||||
} else {
|
||||
device.getIntegerList().add(model);
|
||||
}
|
||||
} else if (datatypeJson.getString("type").equals("bool")) {
|
||||
BoolModelOutput model = new BoolModelOutput();
|
||||
BeanUtils.copyProperties(thingsModel, model);
|
||||
model.setFalseText(datatypeJson.getString("falseText"));
|
||||
model.setTrueText(datatypeJson.getString("trueText"));
|
||||
if (model.getIsMonitor() == 1 || isOnlyRead == true) {
|
||||
ReadOnlyModelOutput readonlyModel = new ReadOnlyModelOutput();
|
||||
BeanUtils.copyProperties(model, readonlyModel);
|
||||
device.getReadOnlyList().add(readonlyModel);
|
||||
} else {
|
||||
device.getBoolList().add(model);
|
||||
}
|
||||
} else if (datatypeJson.getString("type").equals("string")) {
|
||||
StringModelOutput model = new StringModelOutput();
|
||||
BeanUtils.copyProperties(thingsModel, model);
|
||||
model.setMaxLength(datatypeJson.getInteger("maxLength"));
|
||||
if (model.getIsMonitor() == 1 || isOnlyRead == true) {
|
||||
ReadOnlyModelOutput readonlyModel = new ReadOnlyModelOutput();
|
||||
BeanUtils.copyProperties(model, readonlyModel);
|
||||
device.getReadOnlyList().add(readonlyModel);
|
||||
} else {
|
||||
device.getStringList().add(model);
|
||||
}
|
||||
} else if (datatypeJson.getString("type").equals("array")) {
|
||||
ArrayModelOutput model = new ArrayModelOutput();
|
||||
BeanUtils.copyProperties(thingsModel, model);
|
||||
model.setArrayType(datatypeJson.getString("arrayType"));
|
||||
if (model.getIsMonitor() == 1 || isOnlyRead == true) {
|
||||
ReadOnlyModelOutput readonlyModel = new ReadOnlyModelOutput();
|
||||
BeanUtils.copyProperties(model, readonlyModel);
|
||||
device.getReadOnlyList().add(readonlyModel);
|
||||
} else {
|
||||
device.getArrayList().add(model);
|
||||
}
|
||||
} else if (datatypeJson.getString("type").equals("enum")) {
|
||||
EnumModelOutput model = new EnumModelOutput();
|
||||
BeanUtils.copyProperties(thingsModel, model);
|
||||
List<EnumItemOutput> enumItemList = JSONObject.parseArray(datatypeJson.getString("enumList"), EnumItemOutput.class);
|
||||
model.setEnumList(enumItemList);
|
||||
if (model.getIsMonitor() == 1 || isOnlyRead == true) {
|
||||
ReadOnlyModelOutput readonlyModel = new ReadOnlyModelOutput();
|
||||
BeanUtils.copyProperties(model, readonlyModel);
|
||||
device.getReadOnlyList().add(readonlyModel);
|
||||
} else {
|
||||
device.getEnumList().add(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
device.setReadOnlyList(device.getReadOnlyList().stream().sorted(Comparator.comparing(ThingsModelItemBase::getIsMonitor).reversed()).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Device insertDevice(Device device) {
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
//添加设备
|
||||
device.setCreateTime(DateUtils.getNowDate());
|
||||
device.setThingsModelValue(JSONObject.toJSONString(getThingsModelDefaultValue(device.getProductId())));
|
||||
device.setUserId(sysUser.getUserId());
|
||||
device.setUserName(sysUser.getUserName());
|
||||
device.setTenantId(sysUser.getUserId());
|
||||
device.setTenantName(sysUser.getUserName());
|
||||
device.setRssi(0);
|
||||
deviceMapper.insertDevice(device);
|
||||
// 添加设备用户
|
||||
// DeviceUser deviceUser = new DeviceUser();
|
||||
// deviceUser.setUserId(sysUser.getUserId());
|
||||
// deviceUser.setUserName(sysUser.getUserName());
|
||||
// deviceUser.setPhonenumber(sysUser.getPhonenumber());
|
||||
// deviceUser.setDeviceId(device.getDeviceId());
|
||||
// deviceUser.setDeviceName(device.getDeviceName());
|
||||
// deviceUser.setTenantId(device.getDeviceId());
|
||||
// deviceUser.setTenantName(device.getTenantName());
|
||||
// deviceUser.setIsOwner(1);
|
||||
// deviceUserMapper.insertDeviceUser(deviceUser);
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备认证后自动添加设备
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDeviceAuto(String serialNumber,Long userId,Long productId) {
|
||||
Device device = new Device();
|
||||
int random = (int) (Math.random() * (9000)) + 1000;
|
||||
device.setDeviceName("设备" + random);
|
||||
device.setSerialNumber(serialNumber);
|
||||
SysUser user=userService.selectUserById(userId);
|
||||
device.setUserId(userId);
|
||||
device.setUserName(user.getUserName());
|
||||
Product product=productService.selectProductByProductId(productId);
|
||||
device.setProductId(productId);
|
||||
device.setProductName(product.getProductName());
|
||||
device.setTenantId(userId);
|
||||
device.setTenantName(user.getUserName());
|
||||
device.setFirmwareVersion(BigDecimal.valueOf(1.0));
|
||||
device.setStatus(3);
|
||||
device.setActiveTime(DateUtils.getNowDate());
|
||||
device.setIsShadow(0);
|
||||
device.setRssi(0);
|
||||
device.setIsCustomLocation(0);
|
||||
device.setCreateTime(DateUtils.getNowDate());
|
||||
device.setThingsModelValue(JSONObject.toJSONString(getThingsModelDefaultValue(device.getProductId())));
|
||||
return deviceMapper.insertDevice(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物模型值
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
private List<ThingsModelValueItem> getThingsModelDefaultValue(Long productId) {
|
||||
// 获取物模型,设置默认值
|
||||
String thingsModels = thingsModelService.getCacheThingsModelByProductId(productId);
|
||||
JSONObject thingsModelObject = JSONObject.parseObject(thingsModels);
|
||||
JSONArray properties = thingsModelObject.getJSONArray("properties");
|
||||
JSONArray functions = thingsModelObject.getJSONArray("functions");
|
||||
List<ThingsModelValueItem> valueList = properties.toJavaList(ThingsModelValueItem.class);
|
||||
valueList.addAll(functions.toJavaList(ThingsModelValueItem.class));
|
||||
valueList.forEach(x -> {
|
||||
x.setValue("");
|
||||
x.setShadow("");
|
||||
});
|
||||
return valueList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备设置的影子
|
||||
* @param device
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ThingsModelShadow getDeviceShadowThingsModel(Device device) {
|
||||
// 物模型
|
||||
String thingsModels = thingsModelService.getCacheThingsModelByProductId(device.getProductId());
|
||||
JSONObject thingsModelObject = JSONObject.parseObject(thingsModels);
|
||||
JSONArray properties = thingsModelObject.getJSONArray("properties");
|
||||
JSONArray functions = thingsModelObject.getJSONArray("functions");
|
||||
|
||||
// 物模型值
|
||||
List<ThingsModelValueItem> thingsModelValueItems = JSONObject.parseArray(device.getThingsModelValue(), ThingsModelValueItem.class);
|
||||
|
||||
// 查询出设置的影子值
|
||||
List<ThingsModelValueItem> shadowList = new ArrayList<>();
|
||||
for (int i = 0; i < thingsModelValueItems.size(); i++) {
|
||||
if (!thingsModelValueItems.get(i).getValue().equals(thingsModelValueItems.get(i).getShadow())) {
|
||||
shadowList.add(thingsModelValueItems.get(i));
|
||||
System.out.println("添加影子:"+thingsModelValueItems.get(i).getId());
|
||||
}
|
||||
}
|
||||
ThingsModelShadow shadow=new ThingsModelShadow();
|
||||
for (int i = 0; i < shadowList.size(); i++) {
|
||||
boolean isGetValue = false;
|
||||
for (int j = 0; j < properties.size(); j++) {
|
||||
if (properties.getJSONObject(j).getInteger("isMonitor")==0 && properties.getJSONObject(j).getString("id").equals(shadowList.get(i).getId())) {
|
||||
IdentityAndName item = new IdentityAndName(shadowList.get(i).getId(), shadowList.get(i).getShadow());
|
||||
shadow.getProperties().add(item);
|
||||
System.out.println("添加影子属性:"+item.getId());
|
||||
isGetValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isGetValue) {
|
||||
for (int k = 0; k < functions.size(); k++) {
|
||||
if (functions.getJSONObject(k).getString("id").equals(shadowList.get(i).getId())) {
|
||||
IdentityAndName item = new IdentityAndName(shadowList.get(i).getId(), shadowList.get(i).getShadow());
|
||||
shadow.getFunctions().add(item);
|
||||
System.out.println("添加影子功能:"+item.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDevice(Device device) {
|
||||
device.setUpdateTime(DateUtils.getNowDate());
|
||||
// 未激活状态,可以修改产品以及物模型值
|
||||
if (device.getStatus() == 1) {
|
||||
device.setThingsModelValue(JSONObject.toJSONString(getThingsModelDefaultValue(device.getProductId())));
|
||||
} else {
|
||||
device.setProductId(null);
|
||||
device.setProductName(null);
|
||||
}
|
||||
return deviceMapper.updateDevice(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备唯一编号
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public String generationDeviceNum() {
|
||||
String number= "D"+toolService.getStringRandom(15);
|
||||
int count= deviceMapper.getDeviceNumCount(number);
|
||||
if(count==0) {
|
||||
return number;
|
||||
}else{
|
||||
generationDeviceNum();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateDeviceStatusAndLocation(Device device,String ipAddress) {
|
||||
// 设置定位和状态
|
||||
if(ipAddress!="") {
|
||||
if(device.getActiveTime()==null){
|
||||
device.setActiveTime(DateUtils.getNowDate());
|
||||
}
|
||||
if (device.getIsCustomLocation() == 0) {
|
||||
device.setNetworkIp(ipAddress);
|
||||
setLocation(ipAddress, device);
|
||||
}
|
||||
}
|
||||
int result=deviceMapper.updateDeviceStatus(device);
|
||||
|
||||
// 添加到设备日志
|
||||
DeviceLog deviceLog = new DeviceLog();
|
||||
deviceLog.setDeviceId(device.getDeviceId());
|
||||
deviceLog.setDeviceName(device.getDeviceName());
|
||||
deviceLog.setSerialNumber(device.getSerialNumber());
|
||||
deviceLog.setIsMonitor(0);
|
||||
if(device.getStatus()==3){
|
||||
deviceLog.setLogValue("1");
|
||||
deviceLog.setRemark("设备上线");
|
||||
deviceLog.setIdentity("online");
|
||||
deviceLog.setLogType(5);
|
||||
}else if(device.getStatus()==4){
|
||||
deviceLog.setLogValue("0");
|
||||
deviceLog.setRemark("设备离线");
|
||||
deviceLog.setIdentity("offline");
|
||||
deviceLog.setLogType(6);
|
||||
}
|
||||
deviceLogService.insertDeviceLog(deviceLog);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据IP获取地址
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
private void setLocation(String ip,Device device){
|
||||
String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
|
||||
String address = "未知地址";
|
||||
// 内网不查询
|
||||
if (IpUtils.internalIp(ip))
|
||||
{
|
||||
device.setNetworkAddress( "内网IP");
|
||||
}
|
||||
try
|
||||
{
|
||||
String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
|
||||
if (!StringUtils.isEmpty(rspStr))
|
||||
{
|
||||
JSONObject obj = JSONObject.parseObject(rspStr);
|
||||
device.setNetworkAddress(obj.getString("addr"));
|
||||
System.out.println(device.getSerialNumber()+"- 设置地址:"+obj.getString("addr"));
|
||||
// 查询经纬度
|
||||
setLatitudeAndLongitude(obj.getString("city"),device);
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置经纬度
|
||||
* @param city
|
||||
*/
|
||||
private void setLatitudeAndLongitude(String city,Device device){
|
||||
String BAIDU_URL="https://api.map.baidu.com/geocoder";
|
||||
String baiduResponse = HttpUtils.sendGet(BAIDU_URL,"address="+city + "&output=json", Constants.GBK);
|
||||
if(!StringUtils.isEmpty(baiduResponse)){
|
||||
JSONObject baiduObject = JSONObject.parseObject(baiduResponse);
|
||||
JSONObject location=baiduObject.getJSONObject("result").getJSONObject("location");
|
||||
device.setLongitude(location.getBigDecimal("lng"));
|
||||
device.setLatitude(location.getBigDecimal("lat"));
|
||||
System.out.println(device.getSerialNumber()+"- 设置经度:"+location.getBigDecimal("lng")+",设置纬度:"+location.getBigDecimal("lat"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报设备信息
|
||||
* @param device 设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int reportDevice(Device device) {
|
||||
Device deviceEntity=deviceMapper.selectDeviceBySerialNumber(device.getSerialNumber());
|
||||
int result=0;
|
||||
if(deviceEntity!=null){
|
||||
// 更新设备信息
|
||||
device.setUpdateTime(DateUtils.getNowDate());
|
||||
if(deviceEntity.getActiveTime()==null || deviceEntity.getActiveTime().equals("")) {
|
||||
device.setActiveTime(DateUtils.getNowDate());
|
||||
}
|
||||
device.setThingsModelValue(null);
|
||||
result= deviceMapper.updateDeviceBySerialNumber(device);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除设备
|
||||
* @param deviceIds 需要删除的设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteDeviceByDeviceIds(Long[] deviceIds) throws SchedulerException {
|
||||
// 删除设备分组
|
||||
deviceMapper.deleteDeviceGroupByDeviceIds(deviceIds);
|
||||
// 删除设备日志
|
||||
deviceLogMapper.deleteDeviceLogByDeviceIds(deviceIds);
|
||||
// 删除定时任务
|
||||
deviceJobService.deleteJobByDeviceIds(deviceIds);
|
||||
|
||||
// TODO 删除设备用户
|
||||
return deviceMapper.deleteDeviceByDeviceIds(deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备信息
|
||||
* @param deviceId 设备主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceByDeviceId(Long deviceId) {
|
||||
return deviceMapper.deleteDeviceByDeviceId(deviceId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.DeviceUser;
|
||||
import com.ruoyi.iot.mapper.DeviceUserMapper;
|
||||
import com.ruoyi.iot.service.IDeviceUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 设备用户Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class DeviceUserServiceImpl implements IDeviceUserService
|
||||
{
|
||||
@Autowired
|
||||
private DeviceUserMapper deviceUserMapper;
|
||||
|
||||
/**
|
||||
* 查询设备用户
|
||||
*
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 设备用户
|
||||
*/
|
||||
@Override
|
||||
public DeviceUser selectDeviceUserByDeviceId(Long deviceId)
|
||||
{
|
||||
return deviceUserMapper.selectDeviceUserByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备用户列表
|
||||
*
|
||||
* @param deviceUser 设备用户
|
||||
* @return 设备用户
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceUser> selectDeviceUserList(DeviceUser deviceUser)
|
||||
{
|
||||
return deviceUserMapper.selectDeviceUserList(deviceUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备用户
|
||||
*
|
||||
* @param deviceUser 设备用户
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDeviceUser(DeviceUser deviceUser)
|
||||
{
|
||||
deviceUser.setCreateTime(DateUtils.getNowDate());
|
||||
deviceUser.setIsOwner(0);
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
deviceUser.setTenantId(sysUser.getUserId());
|
||||
deviceUser.setTenantName(sysUser.getUserName());
|
||||
return deviceUserMapper.insertDeviceUser(deviceUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备用户
|
||||
*
|
||||
* @param deviceUser 设备用户
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDeviceUser(DeviceUser deviceUser)
|
||||
{
|
||||
deviceUser.setUpdateTime(DateUtils.getNowDate());
|
||||
return deviceUserMapper.updateDeviceUser(deviceUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除设备用户
|
||||
*
|
||||
* @param deviceIds 需要删除的设备用户主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceUserByDeviceIds(Long[] deviceIds)
|
||||
{
|
||||
return deviceUserMapper.deleteDeviceUserByDeviceIds(deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备用户信息
|
||||
*
|
||||
* @param deviceId 设备用户主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeviceUserByDeviceId(Long deviceId)
|
||||
{
|
||||
return deviceUserMapper.deleteDeviceUserByDeviceId(deviceId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.FirmwareMapper;
|
||||
import com.ruoyi.iot.domain.Firmware;
|
||||
import com.ruoyi.iot.service.IFirmwareService;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 产品固件Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class FirmwareServiceImpl implements IFirmwareService
|
||||
{
|
||||
@Autowired
|
||||
private FirmwareMapper firmwareMapper;
|
||||
|
||||
/**
|
||||
* 查询产品固件
|
||||
*
|
||||
* @param firmwareId 产品固件主键
|
||||
* @return 产品固件
|
||||
*/
|
||||
@Override
|
||||
public Firmware selectFirmwareByFirmwareId(Long firmwareId)
|
||||
{
|
||||
return firmwareMapper.selectFirmwareByFirmwareId(firmwareId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品固件列表
|
||||
*
|
||||
* @param firmware 产品固件
|
||||
* @return 产品固件
|
||||
*/
|
||||
@Override
|
||||
public List<Firmware> selectFirmwareList(Firmware firmware)
|
||||
{
|
||||
return firmwareMapper.selectFirmwareList(firmware);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品固件
|
||||
*
|
||||
* @param firmware 产品固件
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertFirmware(Firmware firmware)
|
||||
{
|
||||
SysUser user = getLoginUser().getUser();
|
||||
List<SysRole> roles=user.getRoles();
|
||||
if(roles==null || roles.size()==0) {return 0;}
|
||||
// 系统管理员
|
||||
if(roles.stream().anyMatch(a->a.getRoleKey().equals("admin"))){
|
||||
firmware.setIsSys(1);
|
||||
}
|
||||
firmware.setTenantId(user.getUserId());
|
||||
firmware.setTenantName(user.getUserName());
|
||||
firmware.setCreateTime(DateUtils.getNowDate());
|
||||
return firmwareMapper.insertFirmware(firmware);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品固件
|
||||
*
|
||||
* @param firmware 产品固件
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateFirmware(Firmware firmware)
|
||||
{
|
||||
firmware.setUpdateTime(DateUtils.getNowDate());
|
||||
return firmwareMapper.updateFirmware(firmware);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除产品固件
|
||||
*
|
||||
* @param firmwareIds 需要删除的产品固件主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteFirmwareByFirmwareIds(Long[] firmwareIds)
|
||||
{
|
||||
return firmwareMapper.deleteFirmwareByFirmwareIds(firmwareIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品固件信息
|
||||
*
|
||||
* @param firmwareId 产品固件主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteFirmwareByFirmwareId(Long firmwareId)
|
||||
{
|
||||
return firmwareMapper.deleteFirmwareByFirmwareId(firmwareId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.Group;
|
||||
import com.ruoyi.iot.mapper.GroupMapper;
|
||||
import com.ruoyi.iot.model.DeviceGroupInput;
|
||||
import com.ruoyi.iot.model.IdOutput;
|
||||
import com.ruoyi.iot.service.IGroupService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 设备分组Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class GroupServiceImpl implements IGroupService
|
||||
{
|
||||
@Autowired
|
||||
private GroupMapper groupMapper;
|
||||
|
||||
/**
|
||||
* 查询设备分组
|
||||
*
|
||||
* @param groupId 设备分组主键
|
||||
* @return 设备分组
|
||||
*/
|
||||
@Override
|
||||
public Group selectGroupByGroupId(Long groupId)
|
||||
{
|
||||
return groupMapper.selectGroupByGroupId(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分组ID查询关联的设备ID数组
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Long[] selectDeviceIdsByGroupId(Long groupId){
|
||||
List<IdOutput> list=groupMapper.selectDeviceIdsByGroupId(groupId);
|
||||
Long[] ids=new Long[list.size()];
|
||||
for(int i=0;i<list.size();i++){
|
||||
ids[i]=list.get(i).getId();
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备分组列表
|
||||
*
|
||||
* @param group 设备分组
|
||||
* @return 设备分组
|
||||
*/
|
||||
@Override
|
||||
public List<Group> selectGroupList(Group group)
|
||||
{
|
||||
return groupMapper.selectGroupList(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备分组
|
||||
*
|
||||
* @param group 设备分组
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertGroup(Group group)
|
||||
{
|
||||
SysUser user = getLoginUser().getUser();
|
||||
group.setUserId(user.getUserId());
|
||||
group.setUserName(user.getUserName());
|
||||
group.setCreateTime(DateUtils.getNowDate());
|
||||
return groupMapper.insertGroup(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备分组
|
||||
*
|
||||
* @param group 设备分组
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGroup(Group group)
|
||||
{
|
||||
group.setUpdateTime(DateUtils.getNowDate());
|
||||
return groupMapper.updateGroup(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组下批量添加设备分组
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public int updateDeviceGroups(DeviceGroupInput input){
|
||||
//删除分组下的所有关联设备
|
||||
groupMapper.deleteDeviceGroupByGroupIds(new Long[]{input.getGroupId()});
|
||||
// 分组下添加关联设备
|
||||
if(input.getDeviceIds().length>0){
|
||||
groupMapper.insertDeviceGroups(input);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除分组和设备分组
|
||||
*
|
||||
* @param groupIds 需要删除的设备分组主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteGroupByGroupIds(Long[] groupIds)
|
||||
{
|
||||
// 删除设备分组
|
||||
groupMapper.deleteDeviceGroupByGroupIds(groupIds);
|
||||
// 删除分组
|
||||
return groupMapper.deleteGroupByGroupIds(groupIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分组信息
|
||||
*
|
||||
* @param groupId 设备分组主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteGroupByGroupId(Long groupId)
|
||||
{
|
||||
|
||||
return groupMapper.deleteGroupByGroupId(groupId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.OauthClientDetailsMapper;
|
||||
import com.ruoyi.iot.domain.OauthClientDetails;
|
||||
import com.ruoyi.iot.service.IOauthClientDetailsService;
|
||||
|
||||
/**
|
||||
* 云云对接Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-02-07
|
||||
*/
|
||||
@Service
|
||||
public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService
|
||||
{
|
||||
@Autowired
|
||||
private OauthClientDetailsMapper oauthClientDetailsMapper;
|
||||
|
||||
/**
|
||||
* 查询云云对接
|
||||
*
|
||||
* @param clientId 云云对接主键
|
||||
* @return 云云对接
|
||||
*/
|
||||
@Override
|
||||
public OauthClientDetails selectOauthClientDetailsByClientId(String clientId)
|
||||
{
|
||||
return oauthClientDetailsMapper.selectOauthClientDetailsByClientId(clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询云云对接列表
|
||||
*
|
||||
* @param oauthClientDetails 云云对接
|
||||
* @return 云云对接
|
||||
*/
|
||||
@Override
|
||||
public List<OauthClientDetails> selectOauthClientDetailsList(OauthClientDetails oauthClientDetails)
|
||||
{
|
||||
return oauthClientDetailsMapper.selectOauthClientDetailsList(oauthClientDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增云云对接
|
||||
*
|
||||
* @param oauthClientDetails 云云对接
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertOauthClientDetails(OauthClientDetails oauthClientDetails)
|
||||
{
|
||||
return oauthClientDetailsMapper.insertOauthClientDetails(oauthClientDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改云云对接
|
||||
*
|
||||
* @param oauthClientDetails 云云对接
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateOauthClientDetails(OauthClientDetails oauthClientDetails)
|
||||
{
|
||||
return oauthClientDetailsMapper.updateOauthClientDetails(oauthClientDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除云云对接
|
||||
*
|
||||
* @param clientIds 需要删除的云云对接主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteOauthClientDetailsByClientIds(String[] clientIds)
|
||||
{
|
||||
return oauthClientDetailsMapper.deleteOauthClientDetailsByClientIds(clientIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除云云对接信息
|
||||
*
|
||||
* @param clientId 云云对接主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteOauthClientDetailsByClientId(String clientId)
|
||||
{
|
||||
return oauthClientDetailsMapper.deleteOauthClientDetailsByClientId(clientId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.Product;
|
||||
import com.ruoyi.iot.mapper.ProductMapper;
|
||||
import com.ruoyi.iot.model.ChangeProductStatusModel;
|
||||
import com.ruoyi.iot.model.IdAndName;
|
||||
import com.ruoyi.iot.service.IProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 产品Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class ProductServiceImpl implements IProductService
|
||||
{
|
||||
private String tslPreKey ="tsl";
|
||||
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private ToolServiceImpl toolService;
|
||||
|
||||
/**
|
||||
* 查询产品
|
||||
*
|
||||
* @param productId 产品主键
|
||||
* @return 产品
|
||||
*/
|
||||
@Override
|
||||
public Product selectProductByProductId(Long productId)
|
||||
{
|
||||
return productMapper.selectProductByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品列表
|
||||
*
|
||||
* @param product 产品
|
||||
* @return 产品
|
||||
*/
|
||||
@Override
|
||||
public List<Product> selectProductList(Product product)
|
||||
{
|
||||
return productMapper.selectProductList(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品简短列表
|
||||
*
|
||||
* @return 产品
|
||||
*/
|
||||
@Override
|
||||
public List<IdAndName> selectProductShortList()
|
||||
{
|
||||
SysUser user = getLoginUser().getUser();
|
||||
return productMapper.selectProductShortList(user.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品
|
||||
*
|
||||
* @param product 产品
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public Product insertProduct(Product product)
|
||||
{
|
||||
SysUser user = getLoginUser().getUser();
|
||||
List<SysRole> roles=user.getRoles();
|
||||
if(roles==null || roles.size()==0) {return null;}
|
||||
// 系统管理员
|
||||
if(roles.stream().anyMatch(a->a.getRoleKey().equals("admin"))){
|
||||
product.setIsSys(1);
|
||||
}
|
||||
// mqtt账号密码
|
||||
product.setMqttAccount("wumei-smart");
|
||||
product.setMqttPassword("P"+toolService.getStringRandom(15));
|
||||
product.setMqttSecret("K"+toolService.getStringRandom(15));
|
||||
product.setStatus(product.getStatus()==null?1:product.getStatus());
|
||||
product.setTenantId(user.getUserId());
|
||||
product.setTenantName(user.getUserName());
|
||||
product.setCreateTime(DateUtils.getNowDate());
|
||||
productMapper.insertProduct(product);
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品
|
||||
*
|
||||
* @param product 产品
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateProduct(Product product)
|
||||
{
|
||||
product.setUpdateTime(DateUtils.getNowDate());
|
||||
return productMapper.updateProduct(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新产品状态,1-未发布,2-已发布
|
||||
*
|
||||
* @param model
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult changeProductStatus(ChangeProductStatusModel model)
|
||||
{
|
||||
if(model.getStatus()==1){
|
||||
// 产品下不能有设备
|
||||
Long[] productIds = new Long[1];
|
||||
productIds[0]=model.getProductId();
|
||||
int deviceCount=productMapper.deviceCountInProducts(productIds);
|
||||
if(deviceCount>0){
|
||||
return AjaxResult.error("取消发布失败,请先删除产品下的设备");
|
||||
}
|
||||
}else if(model.getStatus()==2){
|
||||
// 产品下必须包含物模型
|
||||
int thingsCount=productMapper.thingsCountInProduct(model.getProductId());
|
||||
if(thingsCount==0){
|
||||
return AjaxResult.error("发布失败,请先添加产品的物模型");
|
||||
}
|
||||
}else{
|
||||
return AjaxResult.error("状态更新失败,状态值有误");
|
||||
}
|
||||
if(productMapper.changeProductStatus(model)>0){
|
||||
return AjaxResult.success("操作成功");
|
||||
}
|
||||
return AjaxResult.error("状态更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除产品
|
||||
*
|
||||
* @param productIds 需要删除的产品主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public AjaxResult deleteProductByProductIds(Long[] productIds)
|
||||
{
|
||||
// 删除物模型JSON缓存
|
||||
for(int i=0;i<productIds.length;i++){
|
||||
redisCache.deleteObject(tslPreKey+productIds[i]);
|
||||
}
|
||||
// 产品下不能有固件
|
||||
int firmwareCount=productMapper.firmwareCountInProducts(productIds);
|
||||
if(firmwareCount>0){
|
||||
return AjaxResult.error("删除失败,请先删除对应产品下的固件");
|
||||
}
|
||||
// 产品下不能有设备
|
||||
int deviceCount=productMapper.deviceCountInProducts(productIds);
|
||||
if(deviceCount>0){
|
||||
return AjaxResult.error("删除失败,请先删除对应产品下的设备");
|
||||
}
|
||||
// 删除产品物模型
|
||||
productMapper.deleteProductThingsModelByProductIds(productIds);
|
||||
// 删除产品
|
||||
if(productMapper.deleteProductByProductIds(productIds)>0){
|
||||
return AjaxResult.success("删除成功");
|
||||
}
|
||||
return AjaxResult.error("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品信息
|
||||
*
|
||||
* @param productId 产品主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteProductByProductId(Long productId)
|
||||
{
|
||||
// 删除物模型JSON缓存
|
||||
redisCache.deleteObject(tslPreKey+productId);
|
||||
return productMapper.deleteProductByProductId(productId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.SceneMapper;
|
||||
import com.ruoyi.iot.domain.Scene;
|
||||
import com.ruoyi.iot.service.ISceneService;
|
||||
|
||||
/**
|
||||
* 场景联动Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Service
|
||||
public class SceneServiceImpl implements ISceneService
|
||||
{
|
||||
@Autowired
|
||||
private SceneMapper sceneMapper;
|
||||
|
||||
/**
|
||||
* 查询场景联动
|
||||
*
|
||||
* @param sceneId 场景联动主键
|
||||
* @return 场景联动
|
||||
*/
|
||||
@Override
|
||||
public Scene selectSceneBySceneId(Long sceneId)
|
||||
{
|
||||
return sceneMapper.selectSceneBySceneId(sceneId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询场景联动列表
|
||||
*
|
||||
* @param scene 场景联动
|
||||
* @return 场景联动
|
||||
*/
|
||||
@Override
|
||||
public List<Scene> selectSceneList(Scene scene)
|
||||
{
|
||||
return sceneMapper.selectSceneList(scene);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增场景联动
|
||||
*
|
||||
* @param scene 场景联动
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertScene(Scene scene)
|
||||
{
|
||||
scene.setCreateTime(DateUtils.getNowDate());
|
||||
return sceneMapper.insertScene(scene);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景联动
|
||||
*
|
||||
* @param scene 场景联动
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateScene(Scene scene)
|
||||
{
|
||||
scene.setUpdateTime(DateUtils.getNowDate());
|
||||
return sceneMapper.updateScene(scene);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除场景联动
|
||||
*
|
||||
* @param sceneIds 需要删除的场景联动主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSceneBySceneIds(Long[] sceneIds)
|
||||
{
|
||||
return sceneMapper.deleteSceneBySceneIds(sceneIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景联动信息
|
||||
*
|
||||
* @param sceneId 场景联动主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSceneBySceneId(Long sceneId)
|
||||
{
|
||||
return sceneMapper.deleteSceneBySceneId(sceneId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.iot.domain.Product;
|
||||
import com.ruoyi.iot.domain.ThingsModelTemplate;
|
||||
import com.ruoyi.iot.mapper.ProductMapper;
|
||||
import com.ruoyi.iot.mapper.ThingsModelTemplateMapper;
|
||||
import com.ruoyi.iot.model.ImportThingsModelInput;
|
||||
import com.ruoyi.iot.model.ThingsModels.EventDto;
|
||||
import com.ruoyi.iot.model.ThingsModels.FunctionDto;
|
||||
import com.ruoyi.iot.model.ThingsModels.PropertyDto;
|
||||
import com.ruoyi.iot.model.ThingsModels.ThingsModelsDto;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.ThingsModelMapper;
|
||||
import com.ruoyi.iot.domain.ThingsModel;
|
||||
import com.ruoyi.iot.service.IThingsModelService;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 物模型Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class ThingsModelServiceImpl implements IThingsModelService
|
||||
{
|
||||
private String tslPreKey ="things_model:tsl";
|
||||
|
||||
@Autowired
|
||||
private ThingsModelMapper thingsModelMapper;
|
||||
|
||||
@Autowired
|
||||
private ThingsModelTemplateMapper thingsModelTemplateMapper;
|
||||
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* 查询物模型
|
||||
*
|
||||
* @param modelId 物模型主键
|
||||
* @return 物模型
|
||||
*/
|
||||
@Override
|
||||
public ThingsModel selectThingsModelByModelId(Long modelId)
|
||||
{
|
||||
return thingsModelMapper.selectThingsModelByModelId(modelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询物模型列表
|
||||
*
|
||||
* @param thingsModel 物模型
|
||||
* @return 物模型
|
||||
*/
|
||||
@Override
|
||||
public List<ThingsModel> selectThingsModelList(ThingsModel thingsModel)
|
||||
{
|
||||
return thingsModelMapper.selectThingsModelList(thingsModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增物模型
|
||||
*
|
||||
* @param thingsModel 物模型
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertThingsModel(ThingsModel thingsModel)
|
||||
{
|
||||
// 物模型标识符不能重复 TODO 重复查询待优化
|
||||
ThingsModel input=new ThingsModel();
|
||||
input.setProductId(thingsModel.getProductId());
|
||||
List<ThingsModel> list=thingsModelMapper.selectThingsModelList(input);
|
||||
Boolean isRepeat=list.stream().anyMatch(x->x.getIdentifier().equals(thingsModel.getIdentifier()));
|
||||
if(!isRepeat) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
thingsModel.setTenantId(user.getUserId());
|
||||
thingsModel.setTenantName(user.getUserName());
|
||||
thingsModel.setCreateTime(DateUtils.getNowDate());
|
||||
int result = thingsModelMapper.insertThingsModel(thingsModel);
|
||||
// 更新redis缓存
|
||||
setCacheThingsModelByProductId(thingsModel.getProductId());
|
||||
return result;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入通用物模型
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int importByTemplateIds(ImportThingsModelInput input){
|
||||
// 物模型标识符不能重复 TODO 重复查询待优化
|
||||
ThingsModel inputParameter=new ThingsModel();
|
||||
inputParameter.setProductId(input.getProductId());
|
||||
List<ThingsModel> dbList=thingsModelMapper.selectThingsModelList(inputParameter);
|
||||
|
||||
SysUser user = getLoginUser().getUser();
|
||||
// 根据ID集合获取通用物模型列表
|
||||
List<ThingsModelTemplate> templateList=thingsModelTemplateMapper.selectThingsModelTemplateByTemplateIds(input.getTemplateIds());
|
||||
//转换为产品物模型,并批量插入
|
||||
List<ThingsModel> list=new ArrayList<>();
|
||||
int repeatCount=0;
|
||||
for(ThingsModelTemplate template : templateList){
|
||||
ThingsModel thingsModel= new ThingsModel();
|
||||
BeanUtils.copyProperties(template,thingsModel);
|
||||
thingsModel.setTenantId(user.getUserId());
|
||||
thingsModel.setTenantName(user.getUserName());
|
||||
thingsModel.setCreateTime(DateUtils.getNowDate());
|
||||
thingsModel.setProductId(input.getProductId());
|
||||
thingsModel.setProductName(input.getProductName());
|
||||
thingsModel.setModelId(template.getTemplateId());
|
||||
thingsModel.setModelName(template.getTemplateName());
|
||||
Boolean isRepeat=dbList.stream().anyMatch(x->x.getIdentifier().equals(thingsModel.getIdentifier()));
|
||||
if(isRepeat){
|
||||
repeatCount=repeatCount+1;
|
||||
}else{
|
||||
list.add(thingsModel);
|
||||
}
|
||||
}
|
||||
if(list.size()>0) {
|
||||
thingsModelMapper.insertBatchThingsModel(list);
|
||||
//更新redis缓存
|
||||
setCacheThingsModelByProductId(input.getProductId());
|
||||
}
|
||||
return repeatCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改物模型
|
||||
*
|
||||
* @param thingsModel 物模型
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateThingsModel(ThingsModel thingsModel)
|
||||
{
|
||||
// 物模型标识符不能重复 TODO 重复查询待优化
|
||||
ThingsModel input=new ThingsModel();
|
||||
input.setProductId(thingsModel.getProductId());
|
||||
List<ThingsModel> list=thingsModelMapper.selectThingsModelList(input);
|
||||
Boolean isRepeat=list.stream().anyMatch(x->x.getIdentifier().equals(thingsModel.getIdentifier()) && x.getModelId().longValue()!=thingsModel.getModelId());
|
||||
if(!isRepeat) {
|
||||
thingsModel.setUpdateTime(DateUtils.getNowDate());
|
||||
int result = thingsModelMapper.updateThingsModel(thingsModel);
|
||||
// 更新redis缓存
|
||||
setCacheThingsModelByProductId(thingsModel.getProductId());
|
||||
return result;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除物模型
|
||||
*
|
||||
* @param modelIds 需要删除的物模型主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteThingsModelByModelIds(Long[] modelIds)
|
||||
{
|
||||
ThingsModel thingsModel=thingsModelMapper.selectThingsModelByModelId(modelIds[0]);
|
||||
int result=thingsModelMapper.deleteThingsModelByModelIds(modelIds);
|
||||
// 更新redis缓存
|
||||
setCacheThingsModelByProductId(thingsModel.getProductId());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物模型信息
|
||||
*
|
||||
* @param modelId 物模型主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteThingsModelByModelId(Long modelId)
|
||||
{
|
||||
ThingsModel thingsModel=thingsModelMapper.selectThingsModelByModelId(modelId);
|
||||
int result=thingsModelMapper.deleteThingsModelByModelId(modelId);
|
||||
// 更新redis缓存
|
||||
setCacheThingsModelByProductId(thingsModel.getProductId());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品ID获取JSON物模型
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getCacheThingsModelByProductId(Long productId){
|
||||
// redis获取物模型
|
||||
String thingsModelJson = redisCache.getCacheObject(tslPreKey +productId);
|
||||
if (thingsModelJson != null){
|
||||
return thingsModelJson;
|
||||
}
|
||||
return setCacheThingsModelByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品ID更新JSON物模型
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
private String setCacheThingsModelByProductId(Long productId){
|
||||
// 数据库查询物模型集合
|
||||
ThingsModel model=new ThingsModel();
|
||||
model.setProductId(productId);
|
||||
List<ThingsModel> thingsModels=thingsModelMapper.selectThingsModelList(model);
|
||||
// 转换为物模型
|
||||
ThingsModelsDto thingsModelsDto=new ThingsModelsDto();
|
||||
for(int i=0;i<thingsModels.size();i++){
|
||||
if(thingsModels.get(i).getType()==1){
|
||||
// 属性
|
||||
PropertyDto propertyDto=new PropertyDto();
|
||||
propertyDto.setId(thingsModels.get(i).getIdentifier());
|
||||
propertyDto.setName(thingsModels.get(i).getModelName());
|
||||
propertyDto.setIsMonitor(thingsModels.get(i).getIsMonitor());
|
||||
propertyDto.setIsTop(thingsModels.get(i).getIsTop());
|
||||
propertyDto.setDatatype(JSONObject.parseObject(thingsModels.get(i).getSpecs()));
|
||||
thingsModelsDto.getProperties().add(propertyDto);
|
||||
}else if(thingsModels.get(i).getType()==2){
|
||||
// 功能
|
||||
FunctionDto functionDto=new FunctionDto();
|
||||
functionDto.setId(thingsModels.get(i).getIdentifier());
|
||||
functionDto.setName(thingsModels.get(i).getModelName());
|
||||
functionDto.setIsTop(thingsModels.get(i).getIsTop());
|
||||
functionDto.setDatatype(JSONObject.parseObject(thingsModels.get(i).getSpecs()));
|
||||
thingsModelsDto.getFunctions().add(functionDto);
|
||||
}else if(thingsModels.get(i).getType()==3){
|
||||
// 事件
|
||||
EventDto eventDto=new EventDto();
|
||||
eventDto.setId(thingsModels.get(i).getIdentifier());
|
||||
eventDto.setName(thingsModels.get(i).getModelName());
|
||||
eventDto.setDatatype(JSONObject.parseObject(thingsModels.get(i).getSpecs()));
|
||||
thingsModelsDto.getEvents().add(eventDto);
|
||||
}
|
||||
}
|
||||
JSONObject tslObject= (JSONObject) JSONObject.toJSON(thingsModelsDto);
|
||||
redisCache.setCacheObject(tslPreKey +productId,tslObject.toJSONString());
|
||||
Product product=new Product();
|
||||
product.setProductId(productId);
|
||||
product.setThingsModelsJson(tslObject.toJSONString());
|
||||
productMapper.updateThingsModelJson(product);
|
||||
return tslObject.toJSONString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.iot.mapper.ThingsModelTemplateMapper;
|
||||
import com.ruoyi.iot.domain.ThingsModelTemplate;
|
||||
import com.ruoyi.iot.service.IThingsModelTemplateService;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 通用物模型Service业务层处理
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class ThingsModelTemplateServiceImpl implements IThingsModelTemplateService
|
||||
{
|
||||
@Autowired
|
||||
private ThingsModelTemplateMapper thingsModelTemplateMapper;
|
||||
|
||||
/**
|
||||
* 查询通用物模型
|
||||
*
|
||||
* @param templateId 通用物模型主键
|
||||
* @return 通用物模型
|
||||
*/
|
||||
@Override
|
||||
public ThingsModelTemplate selectThingsModelTemplateByTemplateId(Long templateId)
|
||||
{
|
||||
return thingsModelTemplateMapper.selectThingsModelTemplateByTemplateId(templateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询通用物模型列表
|
||||
*
|
||||
* @param thingsModelTemplate 通用物模型
|
||||
* @return 通用物模型
|
||||
*/
|
||||
@Override
|
||||
public List<ThingsModelTemplate> selectThingsModelTemplateList(ThingsModelTemplate thingsModelTemplate)
|
||||
{
|
||||
return thingsModelTemplateMapper.selectThingsModelTemplateList(thingsModelTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增通用物模型
|
||||
*
|
||||
* @param thingsModelTemplate 通用物模型
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertThingsModelTemplate(ThingsModelTemplate thingsModelTemplate)
|
||||
{
|
||||
SysUser user = getLoginUser().getUser();
|
||||
List<SysRole> roles=user.getRoles();
|
||||
if(roles==null || roles.size()==0) {return 0;}
|
||||
// 系统管理员
|
||||
if(roles.stream().anyMatch(a->a.getRoleKey().equals("admin"))){
|
||||
thingsModelTemplate.setIsSys(1);
|
||||
}
|
||||
thingsModelTemplate.setTenantId(user.getUserId());
|
||||
thingsModelTemplate.setTenantName(user.getUserName());
|
||||
thingsModelTemplate.setCreateTime(DateUtils.getNowDate());
|
||||
return thingsModelTemplateMapper.insertThingsModelTemplate(thingsModelTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改通用物模型
|
||||
*
|
||||
* @param thingsModelTemplate 通用物模型
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateThingsModelTemplate(ThingsModelTemplate thingsModelTemplate)
|
||||
{
|
||||
thingsModelTemplate.setUpdateTime(DateUtils.getNowDate());
|
||||
return thingsModelTemplateMapper.updateThingsModelTemplate(thingsModelTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除通用物模型
|
||||
*
|
||||
* @param templateIds 需要删除的通用物模型主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteThingsModelTemplateByTemplateIds(Long[] templateIds)
|
||||
{
|
||||
return thingsModelTemplateMapper.deleteThingsModelTemplateByTemplateIds(templateIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除通用物模型信息
|
||||
*
|
||||
* @param templateId 通用物模型主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteThingsModelTemplateByTemplateId(Long templateId)
|
||||
{
|
||||
return thingsModelTemplateMapper.deleteThingsModelTemplateByTemplateId(templateId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.exception.user.CaptchaException;
|
||||
import com.ruoyi.common.exception.user.CaptchaExpireException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.manager.AsyncManager;
|
||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||
import com.ruoyi.iot.model.RegisterUserInput;
|
||||
import com.ruoyi.iot.service.IToolService;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Service
|
||||
public class ToolServiceImpl implements IToolService
|
||||
{
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 生成随机数字和字母
|
||||
*/
|
||||
@Override
|
||||
public String getStringRandom(int length) {
|
||||
String val = "";
|
||||
Random random = new Random();
|
||||
//参数length,表示生成几位随机数
|
||||
for(int i = 0; i < length; i++) {
|
||||
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
|
||||
//输出字母还是数字
|
||||
if( "char".equalsIgnoreCase(charOrNum) ) {
|
||||
//输出是大写字母还是小写字母
|
||||
// int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
|
||||
val += (char)(random.nextInt(26) + 65);
|
||||
} else if( "num".equalsIgnoreCase(charOrNum) ) {
|
||||
val += String.valueOf(random.nextInt(10));
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String register(RegisterUserInput registerBody)
|
||||
{
|
||||
String msg = "";
|
||||
String username = registerBody.getUsername();
|
||||
String password = registerBody.getPassword();
|
||||
String phonenumber=registerBody.getPhonenumber();
|
||||
|
||||
boolean captchaOnOff = configService.selectCaptchaOnOff();
|
||||
// 验证码开关
|
||||
if (captchaOnOff)
|
||||
{
|
||||
validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(username))
|
||||
{
|
||||
msg = "用户名不能为空";
|
||||
}
|
||||
else if (StringUtils.isEmpty(password))
|
||||
{
|
||||
msg = "用户密码不能为空";
|
||||
}
|
||||
else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
msg = "账户长度必须在2到20个字符之间";
|
||||
}
|
||||
else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
msg = "密码长度必须在5到20个字符之间";
|
||||
}
|
||||
else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username)))
|
||||
{
|
||||
msg = "保存用户'" + username + "'失败,注册账号已存在";
|
||||
}else if (UserConstants.NOT_UNIQUE.equals(checkPhoneUnique(phonenumber)))
|
||||
{
|
||||
msg = "保存用户'" + username + "'失败,注册手机号码已存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserName(username);
|
||||
sysUser.setNickName(username);
|
||||
sysUser.setPhonenumber(username);
|
||||
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
|
||||
boolean regFlag = userService.registerUser(sysUser);
|
||||
//分配普通用户角色(1=超级管理员,2=设备租户,3=普通用户,4=游客)
|
||||
Long[] roleIds={3L};
|
||||
userService.insertUserAuth(sysUser.getUserId(),roleIds);
|
||||
if (!regFlag)
|
||||
{
|
||||
msg = "注册失败,请联系系统管理人员";
|
||||
}
|
||||
else
|
||||
{
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER,
|
||||
MessageUtils.message("user.register.success")));
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验手机号码是否唯一
|
||||
*
|
||||
* @param phonenumber 手机号码
|
||||
* @return
|
||||
*/
|
||||
public String checkPhoneUnique(String phonenumber)
|
||||
{
|
||||
SysUser info = userMapper.checkPhoneUnique(phonenumber);
|
||||
if (StringUtils.isNotNull(info))
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param code 验证码
|
||||
* @param uuid 唯一标识
|
||||
* @return 结果
|
||||
*/
|
||||
public void validateCaptcha(String username, String code, String uuid)
|
||||
{
|
||||
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
|
||||
String captcha = redisCache.getCacheObject(verifyKey);
|
||||
redisCache.deleteObject(verifyKey);
|
||||
if (captcha == null)
|
||||
{
|
||||
throw new CaptchaExpireException();
|
||||
}
|
||||
if (!code.equalsIgnoreCase(captcha))
|
||||
{
|
||||
throw new CaptchaException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user