第一次提交
This commit is contained in:
42
fastbee-open-api/pom.xml
Normal file
42
fastbee-open-api/pom.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>fastbee</artifactId>
|
||||
<groupId>com.fastbee</groupId>
|
||||
<version>3.8.5</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<artifactId>fastbee-open-api</artifactId>
|
||||
<description>controller层接口</description>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fastbee</groupId>
|
||||
<artifactId>mqtt-broker</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fastbee</groupId>
|
||||
<artifactId>sip-server</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-core</artifactId>
|
||||
<version>${liteflow.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fastbee</groupId>
|
||||
<artifactId>fastbee-ruleEngine</artifactId>
|
||||
<version>3.8.5</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,39 @@
|
||||
package com.fastbee.data.config;
|
||||
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeBo;
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeDelayTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.DelayQueue;
|
||||
|
||||
/**
|
||||
* OTA延迟升级队列
|
||||
*
|
||||
* @author gsb
|
||||
* @date 2022/10/26 10:51
|
||||
*/
|
||||
@Slf4j
|
||||
public class DelayUpgradeQueue {
|
||||
|
||||
/**
|
||||
* 使用springboot的 DelayQueue实现延迟队列(OTA对单个设备延迟升级,提高升级容错率)
|
||||
*/
|
||||
private static DelayQueue<OtaUpgradeDelayTask> queue = new DelayQueue<>();
|
||||
|
||||
public static void offerTask(OtaUpgradeDelayTask task) {
|
||||
try {
|
||||
queue.offer(task);
|
||||
} catch (Exception e) {
|
||||
log.error("OTA任务推送异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static OtaUpgradeDelayTask task() {
|
||||
try {
|
||||
return queue.take();
|
||||
} catch (Exception exception) {
|
||||
log.error("=>OTA任务获取异常");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.fastbee.data.config;
|
||||
|
||||
/**
|
||||
* @author gsb
|
||||
* @date 2022/10/26 11:13
|
||||
*/
|
||||
public class TaskConfig {
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.fastbee.data.config;
|
||||
|
||||
|
||||
import com.fastbee.common.constant.FastBeeConstant;
|
||||
import com.fastbee.common.core.domain.entity.SysMenu;
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeDelayTask;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.data.service.IOtaUpgradeService;
|
||||
import com.fastbee.system.service.ISysMenuService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* OTA升级监听
|
||||
* @author bill
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(3)
|
||||
public class UpGradeListener implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private IOtaUpgradeService otaUpgradeService;
|
||||
@Resource
|
||||
private ISysMenuService menuService;
|
||||
/**
|
||||
* true: 使用netty搭建的mqttBroker false: 使用emq
|
||||
*/
|
||||
@Value("${server.broker.enabled}")
|
||||
private Boolean enabled;
|
||||
|
||||
|
||||
@Async(FastBeeConstant.TASK.DELAY_UPGRADE_TASK)
|
||||
public void listen(){
|
||||
while (true){
|
||||
try {
|
||||
OtaUpgradeDelayTask task = DelayUpgradeQueue.task();
|
||||
if (StringUtils.isNotNull(task)){
|
||||
Date startTime = task.getStartTime();
|
||||
otaUpgradeService.upgrade(task);
|
||||
log.info("=>开始OTA升级时间{}",startTime);
|
||||
}
|
||||
continue;
|
||||
}catch (Exception e){
|
||||
log.error("=>OTA升级监听异常",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("=>OTA监听队列启动成功");
|
||||
// updateMenu();
|
||||
listen();
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换菜单中Emqx控制台和netty管理
|
||||
*/
|
||||
public void updateMenu(){
|
||||
SysMenu sysMenu = new SysMenu();
|
||||
if (enabled){
|
||||
sysMenu.setMenuId(2104L);
|
||||
sysMenu.setVisible("1");
|
||||
menuService.updateMenu(sysMenu);
|
||||
sysMenu.setMenuId(3031L);
|
||||
}else {
|
||||
sysMenu.setMenuId(3031L);
|
||||
sysMenu.setVisible("1");
|
||||
menuService.updateMenu(sysMenu);
|
||||
sysMenu.setMenuId(2104L);
|
||||
}
|
||||
sysMenu.setVisible("0");
|
||||
menuService.updateMenu(sysMenu);
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.Alert;
|
||||
import com.fastbee.iot.domain.Scene;
|
||||
import com.fastbee.iot.service.IAlertService;
|
||||
import com.fastbee.notify.domain.NotifyTemplate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备告警Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Api(tags = "设备告警alert模块")
|
||||
@RestController
|
||||
@RequestMapping("/iot/alert")
|
||||
public class AlertController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IAlertService alertService;
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*/
|
||||
@ApiOperation("查询设备告警列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Alert alert)
|
||||
{
|
||||
startPage();
|
||||
List<Alert> list = alertService.selectAlertList(alert);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*/
|
||||
@ApiOperation("查询设备告警列表")
|
||||
@GetMapping("/getScenesByAlertId/{alertId}")
|
||||
public TableDataInfo getScenesByAlertId(@PathVariable("alertId") Long alertId)
|
||||
{
|
||||
List<Scene> list = alertService.selectScenesByAlertId(alertId);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警通知模版列表
|
||||
*/
|
||||
@ApiOperation("查询告警通知模版列表")
|
||||
@GetMapping("/listNotifyTemplate/{alertId}")
|
||||
public TableDataInfo listNotifyTemplate(@PathVariable("alertId") Long alertId)
|
||||
{
|
||||
List<NotifyTemplate> list = alertService.listNotifyTemplateByAlertId(alertId);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备告警列表
|
||||
*/
|
||||
@ApiOperation("导出设备告警列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:export')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Alert alert)
|
||||
{
|
||||
List<Alert> list = alertService.selectAlertList(alert);
|
||||
ExcelUtil<Alert> util = new ExcelUtil<Alert>(Alert.class);
|
||||
util.exportExcel(response, list, "设备告警数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备告警详细信息
|
||||
*/
|
||||
@ApiOperation("获取设备告警详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:query')")
|
||||
@GetMapping(value = "/{alertId}")
|
||||
public AjaxResult getInfo(@PathVariable("alertId") Long alertId)
|
||||
{
|
||||
return AjaxResult.success(alertService.selectAlertByAlertId(alertId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备告警
|
||||
*/
|
||||
@ApiOperation("新增设备告警")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:add')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody Alert alert)
|
||||
{
|
||||
// 查询所属机构
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (null != user.getDeptId()) {
|
||||
alert.setTenantId(user.getDept().getDeptUserId());
|
||||
alert.setTenantName(user.getDept().getDeptUserName());
|
||||
}
|
||||
return toAjax(alertService.insertAlert(alert));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*/
|
||||
@ApiOperation("修改设备告警")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:edit')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody Alert alert)
|
||||
{
|
||||
return toAjax(alertService.updateAlert(alert));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备告警
|
||||
*/
|
||||
@ApiOperation("删除设备告警")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:remove')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{alertIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] alertIds)
|
||||
{
|
||||
return toAjax(alertService.deleteAlertByAlertIds(alertIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备告警状态
|
||||
* @param alertId 告警id
|
||||
* @param status 状态
|
||||
* @return 结果
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:alert:edit')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/editStatus")
|
||||
public AjaxResult editStatus(Long alertId, Integer status)
|
||||
{
|
||||
return toAjax(alertService.editStatus(alertId, status));
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.fastbee.common.constant.HttpStatus;
|
||||
import com.fastbee.common.core.page.PageDomain;
|
||||
import com.fastbee.common.core.page.TableSupport;
|
||||
import com.fastbee.common.utils.ServletUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.sql.SqlUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.AlertLog;
|
||||
import com.fastbee.iot.service.IAlertLogService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备告警Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Api(tags = "设备告警alertLog模块")
|
||||
@RestController
|
||||
@RequestMapping("/iot/alertLog")
|
||||
public class AlertLogController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IAlertLogService alertLogService;
|
||||
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*/
|
||||
@ApiOperation("查询设备告警列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alertLog:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(AlertLog alertLog)
|
||||
{
|
||||
startPage();
|
||||
List<AlertLog> list = alertLogService.selectAlertLogList(alertLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备告警列表
|
||||
*/
|
||||
@ApiOperation("导出设备告警列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alertLog:export')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, AlertLog alertLog)
|
||||
{
|
||||
List<AlertLog> list = alertLogService.selectAlertLogList(alertLog);
|
||||
ExcelUtil<AlertLog> util = new ExcelUtil<AlertLog>(AlertLog.class);
|
||||
util.exportExcel(response, list, "设备告警数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备告警详细信息
|
||||
*/
|
||||
@ApiOperation("获取设备告警详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alertLog:query')")
|
||||
@GetMapping(value = "/{alertLogId}")
|
||||
public AjaxResult getInfo(@PathVariable("alertLogId") Long alertLogId)
|
||||
{
|
||||
return AjaxResult.success(alertLogService.selectAlertLogByAlertLogId(alertLogId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备告警
|
||||
*/
|
||||
@ApiOperation("新增设备告警")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alertLog:add')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody AlertLog alertLog)
|
||||
{
|
||||
return toAjax(alertLogService.insertAlertLog(alertLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*/
|
||||
@ApiOperation("修改设备告警")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alertLog:edit')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody AlertLog alertLog)
|
||||
{
|
||||
return toAjax(alertLogService.updateAlertLog(alertLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备告警
|
||||
*/
|
||||
@ApiOperation("修改设备告警")
|
||||
@PreAuthorize("@ss.hasPermi('iot:alertLog:remove')")
|
||||
@Log(title = "设备告警", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{alertLogIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] alertLogIds)
|
||||
{
|
||||
return toAjax(alertLogService.deleteAlertLogByAlertLogIds(alertLogIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.Alert;
|
||||
import com.fastbee.iot.service.IAlertService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备告警Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oauth/resource")
|
||||
public class AuthResourceController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 查询设备告警列表
|
||||
*/
|
||||
@GetMapping("/product")
|
||||
public String findAll() {
|
||||
return MessageUtils.message("auth.resource.product.query.success");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.Bridge;
|
||||
import com.fastbee.iot.service.IBridgeService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 数据桥接Controller
|
||||
*
|
||||
* @author zhuangpeng.li
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/bridge")
|
||||
@Api(tags = "数据桥接管理")
|
||||
public class BridgeController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IBridgeService bridgeService;
|
||||
|
||||
/**
|
||||
* 查询数据桥接列表
|
||||
*/
|
||||
@ApiOperation("查询数据桥接列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Bridge bridge)
|
||||
{
|
||||
startPage();
|
||||
List<Bridge> list = bridgeService.selectBridgeList(bridge);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据桥接列表
|
||||
*/
|
||||
@ApiOperation("导出数据桥接列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:export')")
|
||||
@Log(title = "数据桥接", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Bridge bridge)
|
||||
{
|
||||
List<Bridge> list = bridgeService.selectBridgeList(bridge);
|
||||
ExcelUtil<Bridge> util = new ExcelUtil<Bridge>(Bridge.class);
|
||||
util.exportExcel(response, list, "数据桥接数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据桥接详细信息
|
||||
*/
|
||||
@ApiOperation("获取数据桥接详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(bridgeService.selectBridgeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据桥接
|
||||
*/
|
||||
@ApiOperation("新增数据桥接")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:add')")
|
||||
@Log(title = "数据桥接", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody Bridge bridge)
|
||||
{
|
||||
return toAjax(bridgeService.insertBridge(bridge));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据桥接
|
||||
*/
|
||||
@ApiOperation("修改数据桥接")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:edit')")
|
||||
@Log(title = "数据桥接", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody Bridge bridge)
|
||||
{
|
||||
return toAjax(bridgeService.updateBridge(bridge));
|
||||
}
|
||||
|
||||
@ApiOperation("连接数据桥接")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:edit')")
|
||||
@Log(title = "数据桥接", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/connect")
|
||||
public AjaxResult connect(@RequestBody Bridge bridge)
|
||||
{
|
||||
return toAjax(bridgeService.connect(bridge));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据桥接
|
||||
*/
|
||||
@ApiOperation("删除数据桥接")
|
||||
@PreAuthorize("@ss.hasPermi('iot:bridge:remove')")
|
||||
@Log(title = "数据桥接", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(bridgeService.deleteBridgeByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.common.core.domain.entity.SysRole;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.iot.model.IdAndName;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.Category;
|
||||
import com.fastbee.iot.service.ICategoryService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
|
||||
/**
|
||||
* 产品分类Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "产品分类")
|
||||
@RestController
|
||||
@RequestMapping("/iot/category")
|
||||
public class CategoryController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 查询产品分类列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("分类分页列表")
|
||||
public TableDataInfo list(Category category)
|
||||
{
|
||||
Boolean showSenior = category.getShowSenior();
|
||||
if (Objects.isNull(showSenior)){
|
||||
category.setShowSenior(true); //默认展示上级品类
|
||||
}
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
category.setAdmin(SecurityUtils.isAdmin(deptUserId));
|
||||
category.setDeptId(getLoginUser().getDeptId());
|
||||
category.setTenantId(deptUserId);
|
||||
startPage();
|
||||
return getDataTable(categoryService.selectCategoryList(category));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品简短分类列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:list')")
|
||||
@GetMapping("/shortlist")
|
||||
@ApiOperation("分类简短列表")
|
||||
public AjaxResult shortlist(Category category)
|
||||
{
|
||||
Boolean showSenior = category.getShowSenior();
|
||||
if (Objects.isNull(showSenior)){
|
||||
category.setShowSenior(true); //默认展示上级品类
|
||||
}
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
category.setAdmin(SecurityUtils.isAdmin(deptUserId));
|
||||
category.setDeptId(getLoginUser().getDeptId());
|
||||
category.setTenantId(deptUserId);
|
||||
startPage();
|
||||
return AjaxResult.success(categoryService.selectCategoryShortList(category));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出产品分类列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:export')")
|
||||
@Log(title = "产品分类", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出分类")
|
||||
public void export(HttpServletResponse response, Category category)
|
||||
{
|
||||
List<Category> list = categoryService.selectCategoryList(category);
|
||||
ExcelUtil<Category> util = new ExcelUtil<Category>(Category.class);
|
||||
util.exportExcel(response, list, "产品分类数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品分类详细信息
|
||||
*/
|
||||
@ApiOperation("获取分类详情")
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:query')")
|
||||
@GetMapping(value = "/{categoryId}")
|
||||
public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
|
||||
{
|
||||
return AjaxResult.success(categoryService.selectCategoryByCategoryId(categoryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品分类
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:add')")
|
||||
@Log(title = "产品分类", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加分类")
|
||||
public AjaxResult add(@RequestBody Category category)
|
||||
{
|
||||
return toAjax(categoryService.insertCategory(category));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品分类
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:edit')")
|
||||
@Log(title = "产品分类", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改分类")
|
||||
public AjaxResult edit(@RequestBody Category category)
|
||||
{
|
||||
return toAjax(categoryService.updateCategory(category));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品分类
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:category:remove')")
|
||||
@Log(title = "产品分类", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{categoryIds}")
|
||||
@ApiOperation("批量删除分类")
|
||||
public AjaxResult remove(@PathVariable Long[] categoryIds)
|
||||
{
|
||||
return categoryService.deleteCategoryByCategoryIds(categoryIds);
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.CommandPreferences;
|
||||
import com.fastbee.iot.service.ICommandPreferencesService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 指令偏好设置Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-06-29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/preferences")
|
||||
@Api(tags = "指令偏好设置")
|
||||
public class CommandPreferencesController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ICommandPreferencesService commandPreferencesService;
|
||||
|
||||
/**
|
||||
* 查询指令偏好设置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:preferences:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询指令偏好设置列表")
|
||||
public TableDataInfo list(CommandPreferences commandPreferences)
|
||||
{
|
||||
startPage();
|
||||
List<CommandPreferences> list = commandPreferencesService.selectCommandPreferencesList(commandPreferences);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出指令偏好设置列表
|
||||
*/
|
||||
@ApiOperation("导出指令偏好设置列表")
|
||||
@PreAuthorize("@ss.hasPermi('order:preferences:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CommandPreferences commandPreferences)
|
||||
{
|
||||
List<CommandPreferences> list = commandPreferencesService.selectCommandPreferencesList(commandPreferences);
|
||||
ExcelUtil<CommandPreferences> util = new ExcelUtil<CommandPreferences>(CommandPreferences.class);
|
||||
util.exportExcel(response, list, "指令偏好设置数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指令偏好设置详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:preferences:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取指令偏好设置详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(commandPreferencesService.selectCommandPreferencesById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增指令偏好设置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:preferences:add')")
|
||||
@PostMapping
|
||||
@ApiOperation("新增指令偏好设置")
|
||||
public AjaxResult add(@RequestBody CommandPreferences commandPreferences)
|
||||
{
|
||||
return toAjax(commandPreferencesService.insertCommandPreferences(commandPreferences));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改指令偏好设置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:preferences:edit')")
|
||||
@PutMapping
|
||||
@ApiOperation("修改指令偏好设置")
|
||||
public AjaxResult edit(@RequestBody CommandPreferences commandPreferences)
|
||||
{
|
||||
return toAjax(commandPreferencesService.updateCommandPreferences(commandPreferences));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指令偏好设置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:preferences:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除指令偏好设置")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(commandPreferencesService.deleteCommandPreferencesByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.DeviceAlertUser;
|
||||
import com.fastbee.iot.model.DeviceAlertUserVO;
|
||||
import com.fastbee.iot.service.IDeviceAlertUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备告警用户Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/deviceAlertUser")
|
||||
public class DeviceAlertUserController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private IDeviceAlertUserService deviceAlertUserService;
|
||||
|
||||
/**
|
||||
* 查询设备告警用户列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:alert:user:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(DeviceAlertUser deviceAlertUser)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceAlertUser> list = deviceAlertUserService.selectDeviceAlertUserList(deviceAlertUser);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备告警用户详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:alert:user:query')")
|
||||
@GetMapping("/query")
|
||||
public TableDataInfo getUser(SysUser sysUser)
|
||||
{
|
||||
startPage();
|
||||
List<SysUser> list = deviceAlertUserService.selectUserList(sysUser);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备告警用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:alert:user:add')")
|
||||
@Log(title = "设备告警用户", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody DeviceAlertUserVO deviceAlertUserVO)
|
||||
{
|
||||
|
||||
return toAjax(deviceAlertUserService.insertDeviceAlertUser(deviceAlertUserVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备告警用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:alert:user:remove')")
|
||||
@Log(title = "设备告警用户", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping
|
||||
public AjaxResult remove(@RequestParam Long deviceId, @RequestParam Long userId)
|
||||
{
|
||||
return toAjax(deviceAlertUserService.deleteByDeviceIdAndUserId(deviceId, userId));
|
||||
}
|
||||
}
|
@ -0,0 +1,484 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.constant.HttpStatus;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.entity.SysRole;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.model.DeviceAssignmentVO;
|
||||
import com.fastbee.iot.model.DeviceImportVO;
|
||||
import com.fastbee.iot.model.DeviceRelateUserInput;
|
||||
import com.fastbee.iot.model.SerialNumberVO;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import com.fastbee.mq.service.IMqttMessagePublish;
|
||||
import com.fastbee.iot.model.dto.ThingsModelDTO;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import com.fastbee.mq.service.IMqttMessagePublish;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 设备Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "设备管理")
|
||||
@RestController
|
||||
@RequestMapping("/iot/device")
|
||||
public class DeviceController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
// @Lazy
|
||||
@Autowired
|
||||
private IMqttMessagePublish messagePublish;
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("设备分页列表")
|
||||
public TableDataInfo list(Device device)
|
||||
{
|
||||
startPage();
|
||||
// 限制当前用户机构
|
||||
if (null == device.getDeptId()) {
|
||||
device.setDeptId(getLoginUser().getDeptId());
|
||||
}
|
||||
return getDataTable(deviceService.selectDeviceList(device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未分配授权码设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/unAuthlist")
|
||||
@ApiOperation("设备分页列表")
|
||||
public TableDataInfo unAuthlist(Device device)
|
||||
{
|
||||
startPage();
|
||||
if (null == device.getDeptId()) {
|
||||
device.setDeptId(getLoginUser().getDeptId());
|
||||
}
|
||||
return getDataTable(deviceService.selectUnAuthDeviceList(device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分组可添加设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/listByGroup")
|
||||
@ApiOperation("查询分组可添加设备分页列表")
|
||||
public TableDataInfo listByGroup(Device device)
|
||||
{
|
||||
startPage();
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if (null == loginUser.getDeptId()) {
|
||||
device.setTenantId(loginUser.getUserId());
|
||||
return getDataTable(deviceService.listTerminalUserByGroup(device));
|
||||
}
|
||||
if (null == device.getDeptId()) {
|
||||
device.setDeptId(getLoginUser().getDeptId());
|
||||
}
|
||||
return getDataTable(deviceService.selectDeviceListByGroup(device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备简短列表,主页列表数据
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/shortList")
|
||||
@ApiOperation("设备分页简短列表")
|
||||
public TableDataInfo shortList(Device device)
|
||||
{
|
||||
startPage();
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if (null == loginUser.getDeptId()) {
|
||||
// 终端用户查询设备
|
||||
device.setTenantId(loginUser.getUserId());
|
||||
return getDataTable(deviceService.listTerminalUser(device));
|
||||
}
|
||||
if (null == device.getDeptId()) {
|
||||
device.setDeptId(getLoginUser().getDeptId());
|
||||
}
|
||||
if (Objects.isNull(device.getTenantId())){
|
||||
device.setTenantId(getLoginUser().getUserId());
|
||||
}
|
||||
if (null == device.getShowChild()) {
|
||||
device.setShowChild(false);
|
||||
}
|
||||
return getDataTable(deviceService.selectDeviceShortList(device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有设备简短列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/all")
|
||||
@ApiOperation("查询所有设备简短列表")
|
||||
public TableDataInfo allShortList()
|
||||
{
|
||||
Device device = new Device();
|
||||
device.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
|
||||
device.setShowChild(true);
|
||||
return getDataTable(deviceService.selectAllDeviceShortList(device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:export')")
|
||||
@Log(title = "设备", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出设备")
|
||||
public void export(HttpServletResponse response, Device device)
|
||||
{
|
||||
List<Device> list = deviceService.selectDeviceList(device);
|
||||
ExcelUtil<Device> util = new ExcelUtil<Device>(Device.class);
|
||||
util.exportExcel(response, list, "设备数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/{deviceId}")
|
||||
@ApiOperation("获取设备详情")
|
||||
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
|
||||
{
|
||||
Device device = deviceService.selectDeviceByDeviceId(deviceId);
|
||||
// 判断当前用户是否有设备分享权限 (设备所属机构管理员和设备所属用户有权限)
|
||||
LoginUser loginUser = getLoginUser();
|
||||
List<SysRole> roles = loginUser.getUser().getRoles();
|
||||
//判断当前用户是否为设备所属机构管理员
|
||||
if(roles.stream().anyMatch(a-> "admin".equals(a.getRoleKey()))){
|
||||
device.setIsOwner(1);
|
||||
} else {
|
||||
//判断当前用户是否是设备所属用户
|
||||
if (Objects.equals(device.getTenantId(), loginUser.getUserId())){
|
||||
device.setIsOwner(1);
|
||||
}else {
|
||||
device.setIsOwner(0);
|
||||
}
|
||||
}
|
||||
return AjaxResult.success(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备数据同步
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/synchronization/{serialNumber}")
|
||||
@ApiOperation("设备数据同步")
|
||||
public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber)
|
||||
{
|
||||
return AjaxResult.success(messagePublish.deviceSynchronization(serialNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备编号详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/getDeviceBySerialNumber/{serialNumber}")
|
||||
@ApiOperation("根据设备编号获取设备详情")
|
||||
public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber)
|
||||
{
|
||||
return AjaxResult.success(deviceService.selectDeviceBySerialNumber(serialNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备统计信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/statistic")
|
||||
@ApiOperation("获取设备统计信息")
|
||||
public AjaxResult getDeviceStatistic()
|
||||
{
|
||||
return AjaxResult.success(deviceService.selectDeviceStatistic());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/runningStatus")
|
||||
@ApiOperation("获取设备详情和运行状态")
|
||||
public AjaxResult getRunningStatusInfo(Long deviceId)
|
||||
{
|
||||
return AjaxResult.success(deviceService.selectDeviceRunningStatusByDeviceId(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@Log(title = "添加设备", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加设备")
|
||||
public AjaxResult add(@RequestBody Device device)
|
||||
{
|
||||
return AjaxResult.success(deviceService.insertDevice(device));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO --APP
|
||||
* 终端用户绑定设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@Log(title = "设备关联用户", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/relateUser")
|
||||
@ApiOperation("终端-设备关联用户")
|
||||
public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput)
|
||||
{
|
||||
if(deviceRelateUserInput.getUserId()==0 || deviceRelateUserInput.getUserId()==null){
|
||||
return AjaxResult.error(MessageUtils.message("device.user.id.null"));
|
||||
}
|
||||
if(deviceRelateUserInput.getDeviceNumberAndProductIds()==null || deviceRelateUserInput.getDeviceNumberAndProductIds().size()==0){
|
||||
return AjaxResult.error(MessageUtils.message("device.product.id.null"));
|
||||
}
|
||||
return deviceService.deviceRelateUser(deviceRelateUserInput);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
|
||||
@Log(title = "修改设备", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改设备")
|
||||
public AjaxResult edit(@RequestBody Device device)
|
||||
{
|
||||
return deviceService.updateDevice(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置设备状态
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
|
||||
@Log(title = "重置设备状态", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/reset/{serialNumber}")
|
||||
@ApiOperation("重置设备状态")
|
||||
public AjaxResult resetDeviceStatus(@PathVariable String serialNumber)
|
||||
{
|
||||
Device device=new Device();
|
||||
device.setSerialNumber(serialNumber);
|
||||
return toAjax(deviceService.resetDeviceStatus(device.getSerialNumber()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:remove')")
|
||||
@Log(title = "删除设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{deviceIds}")
|
||||
@ApiOperation("批量删除设备")
|
||||
public AjaxResult remove(@PathVariable Long[] deviceIds) throws SchedulerException {
|
||||
return deviceService.deleteDeviceByDeviceId(deviceIds[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备编号
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@GetMapping("/generator")
|
||||
@ApiOperation("生成设备编号")
|
||||
public AjaxResult generatorDeviceNum(Integer type){
|
||||
return AjaxResult.success(MessageUtils.message("operate.success"),deviceService.generationDeviceNum(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备MQTT连接参数
|
||||
* @param deviceId 设备主键id
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping("/getMqttConnectData")
|
||||
@ApiOperation("获取设备MQTT连接参数")
|
||||
public AjaxResult getMqttConnectData(Long deviceId){
|
||||
return AjaxResult.success(deviceService.getMqttConnectData(deviceId));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@ApiOperation("下载设备导入模板")
|
||||
@PostMapping("/uploadTemplate")
|
||||
public void uploadTemplate(HttpServletResponse response, @RequestParam(name = "type") Integer type)
|
||||
{
|
||||
// 1-设备导入;2-设备分配
|
||||
if (1 == type) {
|
||||
ExcelUtil<DeviceImportVO> util = new ExcelUtil<>(DeviceImportVO.class);
|
||||
util.importTemplateExcel(response, "设备导入");
|
||||
} else if (2 == type) {
|
||||
ExcelUtil<DeviceAssignmentVO> util = new ExcelUtil<>(DeviceAssignmentVO.class);
|
||||
util.importTemplateExcel(response, "设备分配");
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@ApiOperation("批量导入设备")
|
||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId) throws Exception
|
||||
{
|
||||
if (null == file) {
|
||||
return error(MessageUtils.message("import.failed.file.null"));
|
||||
}
|
||||
ExcelUtil<DeviceImportVO> util = new ExcelUtil<>(DeviceImportVO.class);
|
||||
List<DeviceImportVO> deviceImportVOList = util.importExcel(file.getInputStream());
|
||||
if (CollectionUtils.isEmpty(deviceImportVOList)) {
|
||||
return error(MessageUtils.message("import.failed.data.null"));
|
||||
}
|
||||
DeviceImportVO deviceImportVO = deviceImportVOList.stream().filter(d -> StringUtils.isEmpty(d.getDeviceName())).findAny().orElse(null);
|
||||
if (null != deviceImportVO) {
|
||||
return error(MessageUtils.message("import.failed.device.name.null"));
|
||||
}
|
||||
String message = deviceService.importDevice(deviceImportVOList, productId);
|
||||
return StringUtils.isEmpty(message) ? success(MessageUtils.message("import.success")) : error(message);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:assignment')")
|
||||
@ApiOperation("批量导入分配设备")
|
||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
@PostMapping("/importAssignmentData")
|
||||
public AjaxResult importAssignmentData(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("productId") Long productId,
|
||||
@RequestParam("deptId") Long deptId) throws Exception
|
||||
{
|
||||
if (null == file) {
|
||||
return error(MessageUtils.message("import.failed.file.null"));
|
||||
}
|
||||
ExcelUtil<DeviceAssignmentVO> util = new ExcelUtil<>(DeviceAssignmentVO.class);
|
||||
List<DeviceAssignmentVO> deviceAssignmentVOS = util.importExcel(file.getInputStream());
|
||||
if (CollectionUtils.isEmpty(deviceAssignmentVOS)) {
|
||||
return error(MessageUtils.message("import.failed.device.name.null"));
|
||||
}
|
||||
DeviceAssignmentVO deviceAssignmentVO = deviceAssignmentVOS.stream().filter(d -> StringUtils.isEmpty(d.getDeviceName())).findAny().orElse(null);
|
||||
if (null != deviceAssignmentVO) {
|
||||
return error(MessageUtils.message("import.failed.device.name.null"));
|
||||
}
|
||||
String message = deviceService.importAssignmentDevice(deviceAssignmentVOS, productId, deptId);
|
||||
return StringUtils.isEmpty(message) ? success(MessageUtils.message("import.success")) : error(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配设备
|
||||
* @param deptId 机构id
|
||||
* @param: deviceIds 设备id字符串
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:assignment')")
|
||||
@ApiOperation("分配设备")
|
||||
@PostMapping("/assignment")
|
||||
public AjaxResult assignment(@RequestParam("deptId") Long deptId,
|
||||
@RequestParam("deviceIds") String deviceIds) {
|
||||
if (null == deptId) {
|
||||
return error(MessageUtils.message("device.dept.id.null"));
|
||||
}
|
||||
if (StringUtils.isEmpty(deviceIds)) {
|
||||
return error(MessageUtils.message("device.id.null"));
|
||||
}
|
||||
return deviceService.assignment(deptId, deviceIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回收设备
|
||||
* @param: deviceIds 设备id字符串
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:recovery')")
|
||||
@ApiOperation("回收设备")
|
||||
@PostMapping("/recovery")
|
||||
public AjaxResult recovery(@RequestParam("deviceIds") String deviceIds,
|
||||
@RequestParam("recoveryDeptId") Long recoveryDeptId) {
|
||||
if (StringUtils.isEmpty(deviceIds)) {
|
||||
return error("请选择设备");
|
||||
}
|
||||
return deviceService.recovery(deviceIds, recoveryDeptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成设备编号
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:batchGenerator')")
|
||||
@PostMapping("/batchGenerator")
|
||||
@ApiOperation("批量生成设备编号")
|
||||
public void batchGeneratorDeviceNum(HttpServletResponse response,
|
||||
@RequestParam("count") Integer count){
|
||||
if (count > 200) {
|
||||
throw new ServiceException("最多只能生成200个!");
|
||||
}
|
||||
List<SerialNumberVO> list = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
SerialNumberVO serialNumberVO = new SerialNumberVO();
|
||||
String serialNumber = deviceService.generationDeviceNum(1);
|
||||
serialNumberVO.setSerialNumber(serialNumber);
|
||||
list.add(serialNumberVO);
|
||||
}
|
||||
ExcelUtil<SerialNumberVO> util = new ExcelUtil<>(SerialNumberVO.class);
|
||||
util.exportExcel(response, list, "设备编号");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询变量概况
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping("/listThingsModel")
|
||||
@ApiOperation("查询变量概况")
|
||||
public TableDataInfo listThingsModel(Integer pageNum, Integer pageSize, Long deviceId, String modelName, Integer type)
|
||||
{
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setMsg("查询成功");
|
||||
List<ThingsModelDTO> thingsModelDTOList = deviceService.listThingsModel(deviceId);
|
||||
if (CollectionUtils.isEmpty(thingsModelDTOList)) {
|
||||
rspData.setRows(thingsModelDTOList);
|
||||
rspData.setTotal(new PageInfo(thingsModelDTOList).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
List<ThingsModelDTO> list1;
|
||||
if (StringUtils.isNotEmpty(modelName)) {
|
||||
list1 = thingsModelDTOList.stream().filter(t -> t.getModelName().contains(modelName)).collect(Collectors.toList());
|
||||
} else {
|
||||
list1 = thingsModelDTOList;
|
||||
}
|
||||
List<ThingsModelDTO> list2;
|
||||
if (null != type) {
|
||||
list2 = list1.stream().filter(t -> t.getType().equals(type)).collect(Collectors.toList());
|
||||
} else {
|
||||
list2 = list1;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(list2)) {
|
||||
List resultList = com.fastbee.common.utils.collection.CollectionUtils.startPage(list2, pageNum, pageSize);
|
||||
rspData.setRows(resultList);
|
||||
} else {
|
||||
rspData.setRows(new ArrayList<>());
|
||||
}
|
||||
rspData.setTotal(new PageInfo(list2).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.exception.job.TaskException;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.DeviceJob;
|
||||
import com.fastbee.iot.service.IDeviceJobService;
|
||||
import com.fastbee.quartz.util.CronUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 调度任务信息操作处理
|
||||
*
|
||||
* @author kerwincui
|
||||
*/
|
||||
@Api(tags = "调度任务信息操作处理模块")
|
||||
@RestController
|
||||
@RequestMapping("/iot/job")
|
||||
public class DeviceJobController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IDeviceJobService jobService;
|
||||
|
||||
/**
|
||||
* 查询定时任务列表
|
||||
*/
|
||||
@ApiOperation("查询定时任务列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(DeviceJob deviceJob)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceJob> list = jobService.selectJobList(deviceJob);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出定时任务列表
|
||||
*/
|
||||
@ApiOperation("导出定时任务列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:export')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DeviceJob deviceJob)
|
||||
{
|
||||
List<DeviceJob> list = jobService.selectJobList(deviceJob);
|
||||
ExcelUtil<DeviceJob> util = new ExcelUtil<DeviceJob>(DeviceJob.class);
|
||||
util.exportExcel(response, list, "定时任务");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取定时任务详细信息
|
||||
*/
|
||||
@ApiOperation("获取定时任务详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:query')")
|
||||
@GetMapping(value = "/{jobId}")
|
||||
public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
||||
{
|
||||
return AjaxResult.success(jobService.selectJobById(jobId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增定时任务
|
||||
*/
|
||||
@ApiOperation("新增定时任务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:add')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody DeviceJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
if (!CronUtils.isValid(job.getCronExpression()))
|
||||
{
|
||||
return error(StringUtils.format(MessageUtils.message("job.add.failed.cron.not.valid"), job.getJobName()));
|
||||
}
|
||||
job.setCreateBy(getUsername());
|
||||
return toAjax(jobService.insertJob(job));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改定时任务
|
||||
*/
|
||||
@ApiOperation("修改定时任务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:edit')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody DeviceJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
if (!CronUtils.isValid(job.getCronExpression()))
|
||||
{
|
||||
return error(StringUtils.format(MessageUtils.message("job.update.failed.cron.not.valid"), job.getJobName()));
|
||||
}
|
||||
job.setUpdateBy(getUsername());
|
||||
return toAjax(jobService.updateJob(job));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务状态修改
|
||||
*/
|
||||
@ApiOperation("定时任务状态修改")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:edit')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody DeviceJob job) throws SchedulerException
|
||||
{
|
||||
DeviceJob newJob = jobService.selectJobById(job.getJobId());
|
||||
newJob.setStatus(job.getStatus());
|
||||
return toAjax(jobService.changeStatus(newJob));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务立即执行一次
|
||||
*/
|
||||
@ApiOperation("定时任务立即执行一次")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:execute')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/run")
|
||||
public AjaxResult run(@RequestBody DeviceJob job) throws SchedulerException
|
||||
{
|
||||
jobService.run(job);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*/
|
||||
@ApiOperation("删除定时任务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:timer:remove')")
|
||||
@Log(title = "定时任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{jobIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
|
||||
{
|
||||
jobService.deleteJobByIds(jobIds);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.annotation.Anonymous;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.DeviceLog;
|
||||
import com.fastbee.iot.model.HistoryModel;
|
||||
import com.fastbee.iot.model.MonitorModel;
|
||||
import com.fastbee.iot.service.IDeviceLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备日志Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Api(tags = "设备日志模块")
|
||||
@RestController
|
||||
@RequestMapping("/iot/deviceLog")
|
||||
public class DeviceLogController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IDeviceLogService deviceLogService;
|
||||
|
||||
/**
|
||||
* 查询设备日志列表
|
||||
*/
|
||||
@ApiOperation("查询设备日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(DeviceLog deviceLog)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceLog> list = deviceLogService.selectDeviceLogList(deviceLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备的监测数据
|
||||
*/
|
||||
@ApiOperation("查询设备的监测数据")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/monitor")
|
||||
public TableDataInfo monitorList(DeviceLog deviceLog)
|
||||
{
|
||||
List<MonitorModel> list = deviceLogService.selectMonitorList(deviceLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备日志列表
|
||||
*/
|
||||
@ApiOperation("导出设备日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:export')")
|
||||
@Log(title = "设备日志", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DeviceLog deviceLog)
|
||||
{
|
||||
List<DeviceLog> list = deviceLogService.selectDeviceLogList(deviceLog);
|
||||
ExcelUtil<DeviceLog> util = new ExcelUtil<DeviceLog>(DeviceLog.class);
|
||||
util.exportExcel(response, list, "设备日志数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备日志详细信息
|
||||
*/
|
||||
@ApiOperation("获取设备日志详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:query')")
|
||||
@GetMapping(value = "/{logId}")
|
||||
public AjaxResult getInfo(@PathVariable("logId") Long logId)
|
||||
{
|
||||
return AjaxResult.success(deviceLogService.selectDeviceLogByLogId(logId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备日志
|
||||
*/
|
||||
@ApiOperation("新增设备日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:add')")
|
||||
@Log(title = "设备日志", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody DeviceLog deviceLog)
|
||||
{
|
||||
return toAjax(deviceLogService.insertDeviceLog(deviceLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备日志
|
||||
*/
|
||||
@ApiOperation("修改设备日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:edit')")
|
||||
@Log(title = "设备日志", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody DeviceLog deviceLog)
|
||||
{
|
||||
return toAjax(deviceLogService.updateDeviceLog(deviceLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备日志
|
||||
*/
|
||||
@ApiOperation("删除设备日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:remove')")
|
||||
@Log(title = "设备日志", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{logIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] logIds)
|
||||
{
|
||||
return toAjax(deviceLogService.deleteDeviceLogByLogIds(logIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备的历史数据
|
||||
*/
|
||||
@ApiOperation("查询设备的历史数据")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/history")
|
||||
public AjaxResult historyList(DeviceLog deviceLog)
|
||||
{
|
||||
Map<String, List<HistoryModel>> resultMap = deviceLogService.selectHistoryList(deviceLog);
|
||||
return AjaxResult.success(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备的历史数据
|
||||
*/
|
||||
@ApiOperation("查询设备的历史数据")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/historyGroupByCreateTime")
|
||||
public TableDataInfo historyGroupByCreateTime(DeviceLog deviceLog)
|
||||
{
|
||||
startPage();
|
||||
List<JSONObject> list = deviceLogService.listhistoryGroupByCreateTime(deviceLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.mq.message.DeviceMessage;
|
||||
import com.fastbee.data.service.IDeviceMessageService;
|
||||
import com.fastbee.modbus.model.ModbusRtu;
|
||||
import com.fastbee.pakModbus.model.PakModbusRtu;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/iot/message")
|
||||
@Api(tags = "设备消息")
|
||||
public class DeviceMessageController extends BaseController {
|
||||
|
||||
@Resource
|
||||
IDeviceMessageService deviceMessageService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:message:post')")
|
||||
@PostMapping(value = "/post")
|
||||
@ApiOperation(value = "平台下发指令")
|
||||
public AjaxResult messagePost(@RequestBody DeviceMessage deviceMessage) {
|
||||
deviceMessageService.messagePost(deviceMessage);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:message:encode')")
|
||||
@GetMapping(value = "/encode")
|
||||
@ApiOperation(value = "指令编码")
|
||||
public AjaxResult messageEncode(ModbusRtu modbusRtu) {
|
||||
return AjaxResult.success(deviceMessageService.messageEncode(modbusRtu));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:message:decode')")
|
||||
@GetMapping(value = "/decode")
|
||||
@ApiOperation(value = "指令解码")
|
||||
public AjaxResult messageDecode(DeviceMessage deviceMessage) {
|
||||
return AjaxResult.success(deviceMessageService.messageDecode(deviceMessage));
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.common.annotation.Anonymous;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.iot.model.DeviceRecordVO;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.DeviceRecord;
|
||||
import com.fastbee.iot.service.IDeviceRecordService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备记录Controller
|
||||
*
|
||||
* @author zhangzhiyi
|
||||
* @date 2024-07-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/record")
|
||||
public class DeviceRecordController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private IDeviceRecordService deviceRecordService;
|
||||
|
||||
/**
|
||||
* 查询设备记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:record:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(DeviceRecord deviceRecord)
|
||||
{
|
||||
startPage();
|
||||
if (null == deviceRecord.getOperateDeptId()) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
deviceRecord.setTenantId(user.getDept().getDeptUserId());
|
||||
}
|
||||
List<DeviceRecordVO> list = deviceRecordService.selectDeviceRecordList(deviceRecord);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:record:export')")
|
||||
@Log(title = "设备记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DeviceRecord deviceRecord)
|
||||
{
|
||||
List<DeviceRecordVO> list = deviceRecordService.selectDeviceRecordList(deviceRecord);
|
||||
ExcelUtil<DeviceRecordVO> util = new ExcelUtil<>(DeviceRecordVO.class);
|
||||
util.exportExcel(response, list, "设备记录数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备记录详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:record:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(deviceRecordService.selectDeviceRecordById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:record:remove')")
|
||||
@Log(title = "设备记录", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(deviceRecordService.deleteDeviceRecordByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.domain.DeviceUser;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.DeviceShare;
|
||||
import com.fastbee.iot.service.IDeviceShareService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备分享Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-04-03
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/share")
|
||||
public class DeviceShareController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IDeviceShareService deviceShareService;
|
||||
|
||||
/**
|
||||
* 查询设备分享列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(DeviceShare deviceShare)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceShare> list = deviceShareService.selectDeviceShareList(deviceShare);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备分享列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:export')")
|
||||
@Log(title = "设备分享", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, DeviceShare deviceShare)
|
||||
{
|
||||
List<DeviceShare> list = deviceShareService.selectDeviceShareList(deviceShare);
|
||||
ExcelUtil<DeviceShare> util = new ExcelUtil<DeviceShare>(DeviceShare.class);
|
||||
util.exportExcel(response, list, "设备分享数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备分享详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:query')")
|
||||
@GetMapping(value = "/detail")
|
||||
public AjaxResult getInfo(Long deviceId,Long userId)
|
||||
{
|
||||
return success(deviceShareService.selectDeviceShareByDeviceIdAndUserId(deviceId,userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备分享
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:add')")
|
||||
@Log(title = "设备分享", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody DeviceShare deviceShare)
|
||||
{
|
||||
return toAjax(deviceShareService.insertDeviceShare(deviceShare));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备分享
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:edit')")
|
||||
@Log(title = "设备分享", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody DeviceShare deviceShare)
|
||||
{
|
||||
return toAjax(deviceShareService.updateDeviceShare(deviceShare));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备分享
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:remove')")
|
||||
@Log(title = "设备分享", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{deviceIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] deviceIds)
|
||||
{
|
||||
return toAjax(deviceShareService.deleteDeviceShareByDeviceIds(deviceIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备分享
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:remove')")
|
||||
@Log(title = "设备分享", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping()
|
||||
public AjaxResult delete(@RequestBody DeviceShare deviceShare)
|
||||
{
|
||||
return toAjax(deviceShareService.deleteDeviceShareByDeviceIdAndUserId(deviceShare));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分享用户信息
|
||||
*/
|
||||
@GetMapping("/shareUser")
|
||||
@PreAuthorize("@ss.hasPermi('iot:share:user')")
|
||||
public AjaxResult userList(DeviceShare share)
|
||||
{
|
||||
return AjaxResult.success(deviceShareService.selectShareUser(share));
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.DeviceUser;
|
||||
import com.fastbee.iot.service.IDeviceUserService;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备用户Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "设备用户")
|
||||
@RestController
|
||||
@RequestMapping("/iot/deviceUser")
|
||||
public class DeviceUserController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IDeviceUserService deviceUserService;
|
||||
|
||||
/**
|
||||
* 查询设备用户列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("设备用户分页列表")
|
||||
public TableDataInfo list(DeviceUser deviceUser)
|
||||
{
|
||||
startPage();
|
||||
List<DeviceUser> list = deviceUserService.selectDeviceUserList(deviceUser);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备分享用户信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:query')")
|
||||
@GetMapping("/shareUser")
|
||||
public AjaxResult userList(DeviceUser user)
|
||||
{
|
||||
return AjaxResult.success(deviceUserService.selectShareUser(user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备用户详细信息 根据deviceId 查询的话可能会查出多个
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:query')")
|
||||
@GetMapping(value = "/{deviceId}")
|
||||
@ApiOperation("获取设备用户详情")
|
||||
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
|
||||
{
|
||||
return AjaxResult.success(deviceUserService.selectDeviceUserByDeviceId(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备用户详细信息 双主键 device_id 和 user_id
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:query')")
|
||||
@GetMapping(value = "/{deviceId}/{userId}")
|
||||
@ApiOperation("获取设备用户详情,根据用户id 和 设备id")
|
||||
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId, @PathVariable("userId") Long userId)
|
||||
{
|
||||
return AjaxResult.success(deviceUserService.selectDeviceUserByDeviceIdAndUserId(deviceId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:share')")
|
||||
@Log(title = "设备用户", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加设备用户")
|
||||
public AjaxResult add(@RequestBody DeviceUser deviceUser)
|
||||
{
|
||||
return toAjax(deviceUserService.insertDeviceUser(deviceUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增多个设备用户
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:share')")
|
||||
@Log(title = "设备用户", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/addDeviceUsers")
|
||||
@ApiOperation("批量添加设备用户")
|
||||
public AjaxResult addDeviceUsers(@RequestBody List<DeviceUser> deviceUsers)
|
||||
{
|
||||
return toAjax(deviceUserService.insertDeviceUserList(deviceUsers));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备用户
|
||||
*/
|
||||
@ApiOperation("修改设备用户")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:edit')")
|
||||
@Log(title = "设备用户", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody DeviceUser deviceUser)
|
||||
{
|
||||
return toAjax(deviceUserService.updateDeviceUser(deviceUser));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备用户
|
||||
*/
|
||||
@ApiOperation("删除设备用户")
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:user:remove')")
|
||||
@Log(title = "设备用户", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping
|
||||
public AjaxResult remove(@RequestBody DeviceUser deviceUser)
|
||||
{
|
||||
int count=deviceUserService.deleteDeviceUser(deviceUser);
|
||||
if(count==0){
|
||||
return AjaxResult.error(MessageUtils.message("device.user.delete.failed.user.not.valid"));
|
||||
}else{
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.domain.EventLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.service.IEventLogService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 事件日志Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2023-03-28
|
||||
*/
|
||||
@Api(tags = "事件日志")
|
||||
@RestController
|
||||
@RequestMapping("/iot/event")
|
||||
public class EventLogController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IEventLogService eventLogService;
|
||||
|
||||
/**
|
||||
* 查询事件日志列表
|
||||
*/
|
||||
@ApiOperation("查询事件日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:event:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(EventLog eventLog)
|
||||
{
|
||||
startPage();
|
||||
List<EventLog> list = eventLogService.selectEventLogList(eventLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出事件日志列表
|
||||
*/
|
||||
@ApiOperation("导出事件日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:event:export')")
|
||||
@Log(title = "事件日志", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, EventLog eventLog)
|
||||
{
|
||||
List<EventLog> list = eventLogService.selectEventLogList(eventLog);
|
||||
ExcelUtil<EventLog> util = new ExcelUtil<EventLog>(EventLog.class);
|
||||
util.exportExcel(response, list, "事件日志数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取事件日志详细信息
|
||||
*/
|
||||
@ApiOperation("获取事件日志详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:event:query')")
|
||||
@GetMapping(value = "/{logId}")
|
||||
public AjaxResult getInfo(@PathVariable("logId") Long logId)
|
||||
{
|
||||
return success(eventLogService.selectEventLogByLogId(logId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增事件日志
|
||||
*/
|
||||
@ApiOperation("新增事件日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:event:add')")
|
||||
@Log(title = "事件日志", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody EventLog eventLog)
|
||||
{
|
||||
return toAjax(eventLogService.insertEventLog(eventLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改事件日志
|
||||
*/
|
||||
@ApiOperation("修改事件日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:event:edit')")
|
||||
@Log(title = "事件日志", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody EventLog eventLog)
|
||||
{
|
||||
return toAjax(eventLogService.updateEventLog(eventLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除事件日志
|
||||
*/
|
||||
@ApiOperation("删除事件日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:event:remove')")
|
||||
@Log(title = "事件日志", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{logIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] logIds)
|
||||
{
|
||||
return toAjax(eventLogService.deleteEventLogByLogIds(logIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.FunctionLog;
|
||||
import com.fastbee.iot.service.IFunctionLogService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备服务下发日志Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-10-22
|
||||
*/
|
||||
@Api(tags = "设备服务下发日志")
|
||||
@RestController
|
||||
@RequestMapping("/iot/log")
|
||||
public class FunctionLogController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IFunctionLogService functionLogService;
|
||||
|
||||
/**
|
||||
* 查询设备服务下发日志列表
|
||||
*/
|
||||
@ApiOperation("查询设备服务下发日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:log:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(FunctionLog functionLog)
|
||||
{
|
||||
startPage();
|
||||
List<FunctionLog> list = functionLogService.selectFunctionLogList(functionLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备服务下发日志列表
|
||||
*/
|
||||
@ApiOperation("导出设备服务下发日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:log:export')")
|
||||
@Log(title = "设备服务下发日志", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, FunctionLog functionLog)
|
||||
{
|
||||
List<FunctionLog> list = functionLogService.selectFunctionLogList(functionLog);
|
||||
ExcelUtil<FunctionLog> util = new ExcelUtil<FunctionLog>(FunctionLog.class);
|
||||
util.exportExcel(response, list, "设备服务下发日志数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备服务下发日志详细信息
|
||||
*/
|
||||
@ApiOperation("获取设备服务下发日志详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:log:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return AjaxResult.success(functionLogService.selectFunctionLogById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备服务下发日志
|
||||
*/
|
||||
@ApiOperation("新增设备服务下发日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:log:add')")
|
||||
@Log(title = "设备服务下发日志", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody FunctionLog functionLog)
|
||||
{
|
||||
return toAjax(functionLogService.insertFunctionLog(functionLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备服务下发日志
|
||||
*/
|
||||
@ApiOperation("修改设备服务下发日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:log:edit')")
|
||||
@Log(title = "设备服务下发日志", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody FunctionLog functionLog)
|
||||
{
|
||||
return toAjax(functionLogService.updateFunctionLog(functionLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备服务下发日志
|
||||
*/
|
||||
@ApiOperation("删除设备服务下发日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:log:remove')")
|
||||
@Log(title = "设备服务下发日志", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(functionLogService.deleteFunctionLogByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.config.RuoYiConfig;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.bean.BeanUtils;
|
||||
import com.fastbee.iot.domain.GoviewProject;
|
||||
import com.fastbee.iot.domain.GoviewProjectData;
|
||||
import com.fastbee.iot.model.goview.GoviewProjectVo;
|
||||
import com.fastbee.iot.service.IGoviewProjectDataService;
|
||||
import com.fastbee.iot.service.IGoviewProjectService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 项目Controller
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-10-27
|
||||
*/
|
||||
@Api(tags = "项目模块")
|
||||
@RestController
|
||||
@RequestMapping("/goview/project")
|
||||
public class GoviewProjectController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IGoviewProjectService goviewProjectService;
|
||||
|
||||
@Autowired
|
||||
private IGoviewProjectDataService goviewProjectDataService;
|
||||
|
||||
/**
|
||||
* 查询项目列表
|
||||
*/
|
||||
@ApiOperation("查询项目列表")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(GoviewProject goviewProject) {
|
||||
startPage();
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (null != user.getDeptId()) {
|
||||
goviewProject.setTenantId(user.getDept().getDeptUserId());
|
||||
} else {
|
||||
goviewProject.setTenantId(user.getUserId());
|
||||
}
|
||||
List<GoviewProject> list = goviewProjectService.selectGoviewProjectList(goviewProject);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目详细信息
|
||||
*/
|
||||
@ApiOperation("获取项目详细信息")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") String id) {
|
||||
return AjaxResult.success(goviewProjectService.selectGoviewProjectById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增项目
|
||||
*/
|
||||
@ApiOperation("新增项目")
|
||||
@Log(title = "项目", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody GoviewProject goviewProject) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (null != user.getDeptId()) {
|
||||
goviewProject.setTenantId(user.getDept().getDeptUserId());
|
||||
goviewProject.setTenantName(user.getDept().getDeptUserName());
|
||||
} else {
|
||||
goviewProject.setTenantId(user.getUserId());
|
||||
goviewProject.setTenantName(user.getUserName());
|
||||
}
|
||||
String projectId = goviewProjectService.insertGoviewProject(goviewProject);
|
||||
if(StringUtils.isNotEmpty(projectId)){
|
||||
return AjaxResult.success(MessageUtils.message("create.success"),goviewProject);
|
||||
}else {
|
||||
return AjaxResult.error(MessageUtils.message("create.failed"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目
|
||||
*/
|
||||
@ApiOperation("修改项目")
|
||||
@Log(title = "项目", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody GoviewProject goviewProject) {
|
||||
return toAjax(goviewProjectService.updateGoviewProject(goviewProject));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
*/
|
||||
@ApiOperation("删除项目")
|
||||
@Log(title = "项目", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable String[] ids) {
|
||||
return toAjax(goviewProjectService.deleteGoviewProjectByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取项目存储数据
|
||||
* @param projectId 项目id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("获取项目存储数据")
|
||||
@GetMapping("/getData")
|
||||
public AjaxResult getData(String projectId) {
|
||||
GoviewProject goviewProject = goviewProjectService.selectGoviewProjectById(projectId);
|
||||
GoviewProjectData projectData = goviewProjectDataService.selectGoviewProjectDataByProjectId(projectId);
|
||||
GoviewProjectVo goviewProjectVo = new GoviewProjectVo();
|
||||
BeanUtils.copyBeanProp(goviewProjectVo,goviewProject);
|
||||
if(projectData != null) {
|
||||
goviewProjectVo.setContent(projectData.getDataToStr());
|
||||
}
|
||||
return AjaxResult.success(goviewProjectVo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存大屏内部数据(字节)
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("保存大屏内部数据")
|
||||
@PostMapping("/save/data")
|
||||
public AjaxResult saveData(GoviewProjectData data) {
|
||||
GoviewProject goviewProject= goviewProjectService.selectGoviewProjectById(data.getProjectId());
|
||||
if(goviewProject == null) {
|
||||
return AjaxResult.error(MessageUtils.message("goview.project.data.save.failed.id.null"));
|
||||
}
|
||||
int i = goviewProjectDataService.insertOrUpdateGoviewProjectData(data);
|
||||
if(i > 0) {
|
||||
return AjaxResult.success(MessageUtils.message("save.success"));
|
||||
}
|
||||
return AjaxResult.error(MessageUtils.message("save.failed"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* goview文件上传(同一个大屏覆盖保存)
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("文件上传")
|
||||
public AjaxResult uploadFile(@RequestBody MultipartFile object) throws Exception {
|
||||
try {
|
||||
String filePath = RuoYiConfig.getProfile();
|
||||
// 获取文件名和文件类型
|
||||
String fileName = object.getOriginalFilename();
|
||||
fileName = "/goview/" + getLoginUser().getUserId().toString() + "/" + fileName;
|
||||
//创建目录
|
||||
File desc = new File(filePath + File.separator + fileName);
|
||||
if (!desc.exists()) {
|
||||
if (!desc.getParentFile().exists()) {
|
||||
desc.getParentFile().mkdirs();
|
||||
}
|
||||
}
|
||||
// 存储文件-覆盖存储(一个文件一个图,防止过多)
|
||||
object.transferTo(desc);
|
||||
String url = "/profile" + fileName;
|
||||
Map<String, Object> map=new HashMap<String, Object>(2);
|
||||
map.put("fileName", url);
|
||||
map.put("url", url);
|
||||
return AjaxResult.success("上传成功",map);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Anonymous;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.iot.service.IGoviewProjectDataService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* goview 获取数据接口
|
||||
* 可自己根据需求在此添加获取数据接口
|
||||
* @author fastb
|
||||
* @date 2023-11-06 15:07
|
||||
*/
|
||||
@Anonymous
|
||||
@Api(tags = "大屏管理获取数据")
|
||||
@RestController
|
||||
@RequestMapping("/goview/projectData")
|
||||
public class GoviewProjectDataController {
|
||||
|
||||
@Resource
|
||||
private IGoviewProjectDataService goviewProjectDataService;
|
||||
|
||||
/**
|
||||
* 根据sql获取组件数据接口
|
||||
* @param sql sql
|
||||
* @return 组件数据
|
||||
*/
|
||||
@PostMapping("/executeSql")
|
||||
public AjaxResult executeSql(@RequestParam String sql) {
|
||||
if (StringUtils.isEmpty(sql)) {
|
||||
return AjaxResult.error(MessageUtils.message("goview.project.data.execute.sql.failed"));
|
||||
}
|
||||
return goviewProjectDataService.executeSql(sql);
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.domain.DeviceGroup;
|
||||
import com.fastbee.iot.model.DeviceGroupInput;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.Group;
|
||||
import com.fastbee.iot.service.IGroupService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备分组Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "设备分组")
|
||||
@RestController
|
||||
@RequestMapping("/iot/group")
|
||||
public class GroupController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IGroupService groupService;
|
||||
|
||||
/**
|
||||
* 查询设备分组列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("分组分页列表")
|
||||
public TableDataInfo list(Group group)
|
||||
{
|
||||
startPage();
|
||||
return getDataTable(groupService.selectGroupList(group));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备分组列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:export')")
|
||||
@Log(title = "分组", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出分组")
|
||||
public void export(HttpServletResponse response, Group group)
|
||||
{
|
||||
List<Group> list = groupService.selectGroupList(group);
|
||||
ExcelUtil<Group> util = new ExcelUtil<Group>(Group.class);
|
||||
util.exportExcel(response, list, "设备分组数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备分组详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:query')")
|
||||
@GetMapping(value = "/{groupId}")
|
||||
@ApiOperation("获取分组详情")
|
||||
public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
|
||||
{
|
||||
return AjaxResult.success(groupService.selectGroupByGroupId(groupId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分组下的所有关联设备ID数组
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:query')")
|
||||
@GetMapping(value = "/getDeviceIds/{groupId}")
|
||||
@ApiOperation("获取分组下的所有关联设备ID数组")
|
||||
public AjaxResult getDeviceIds(@PathVariable("groupId") Long groupId)
|
||||
{
|
||||
return AjaxResult.success(groupService.selectDeviceIdsByGroupId(groupId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备分组
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:add')")
|
||||
@Log(title = "分组", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加分组")
|
||||
public AjaxResult add(@RequestBody Group group)
|
||||
{
|
||||
return toAjax(groupService.insertGroup(group));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分组下的关联设备
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:edit')")
|
||||
@Log(title = "设备分组", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/updateDeviceGroups")
|
||||
@ApiOperation("更新分组下的关联设备")
|
||||
public AjaxResult updateDeviceGroups(@RequestBody DeviceGroupInput input){
|
||||
return toAjax(groupService.updateDeviceGroups(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备分组
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:edit')")
|
||||
@Log(title = "分组", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改分组")
|
||||
public AjaxResult edit(@RequestBody Group group)
|
||||
{
|
||||
return toAjax(groupService.updateGroup(group));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备分组
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:group:remove')")
|
||||
@Log(title = "分组", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{groupIds}")
|
||||
@ApiOperation("批量删除设备分组")
|
||||
public AjaxResult remove(@PathVariable Long[] groupIds)
|
||||
{
|
||||
return toAjax(groupService.deleteGroupByGroupIds(groupIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.iot.model.ScriptCondition;
|
||||
import com.fastbee.iot.ruleEngine.MsgContext;
|
||||
import com.fastbee.iot.service.IScriptService;
|
||||
import com.fastbee.ruleEngine.core.FlowLogExecutor;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/bridge")
|
||||
public class HttpBridgeController {
|
||||
@Resource
|
||||
private IScriptService scriptService;
|
||||
|
||||
@Autowired
|
||||
private FlowLogExecutor flowExecutor;
|
||||
|
||||
@ApiOperation("数据桥接get入口")
|
||||
@GetMapping(value = "/get")
|
||||
public AjaxResult bridgeGet(HttpServletRequest request)
|
||||
{
|
||||
ScriptCondition scriptCondition = ScriptCondition.builder()
|
||||
.scriptPurpose(1)
|
||||
.scriptEvent(5)
|
||||
.route("/bridge/get")
|
||||
.build();
|
||||
MsgContext context = MsgContext.builder().dataMap(buildDataMap(request)).build();
|
||||
//返回处理完的消息上下文
|
||||
return AjaxResult.success(scriptService.execRuleScript(scriptCondition,context));
|
||||
}
|
||||
@ApiOperation("数据桥接put入口")
|
||||
@PutMapping(value = "/put")
|
||||
public AjaxResult bridgePut(HttpServletRequest request, @RequestBody Object body)
|
||||
{
|
||||
ScriptCondition scriptCondition = ScriptCondition.builder()
|
||||
.scriptPurpose(1)
|
||||
.scriptEvent(5)
|
||||
.route("/bridge/put")
|
||||
.build();
|
||||
MsgContext context = MsgContext.builder().dataMap(buildDataMap(request)).payload(body.toString()).build();
|
||||
//返回处理完的消息上下文
|
||||
return AjaxResult.success(scriptService.execRuleScript(scriptCondition,context));
|
||||
}
|
||||
@ApiOperation("数据桥接post入口")
|
||||
@PostMapping(value = "/post")
|
||||
public AjaxResult bridgePost(HttpServletRequest request, @RequestBody Object body)
|
||||
{
|
||||
ScriptCondition scriptCondition = ScriptCondition.builder()
|
||||
.scriptPurpose(1)
|
||||
.scriptEvent(5)
|
||||
.route("/bridge/post")
|
||||
.build();
|
||||
MsgContext context = MsgContext.builder().dataMap(buildDataMap(request)).payload(body.toString()).build();
|
||||
//返回处理完的消息上下文
|
||||
return AjaxResult.success(scriptService.execRuleScript(scriptCondition,context));
|
||||
}
|
||||
|
||||
private ConcurrentHashMap<String, Object> buildDataMap(HttpServletRequest request)
|
||||
{
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
Map<String, List<String>> headers = new HashMap<>();
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String headerName = headerNames.nextElement();
|
||||
headers.put(headerName, Collections.list(request.getHeaders(headerName)));
|
||||
}
|
||||
JSONObject headersjson = new JSONObject(headers);
|
||||
ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<>();
|
||||
dataMap.put("headers", headersjson.toJSONString());
|
||||
JSONObject paramsjson = new JSONObject(request.getParameterMap());
|
||||
dataMap.put("params", paramsjson.toJSONString());
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.model.IdAndName;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.NewsCategory;
|
||||
import com.fastbee.iot.service.INewsCategoryService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 新闻分类Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-04-09
|
||||
*/
|
||||
@Api(tags = "新闻分类")
|
||||
@RestController
|
||||
@RequestMapping("/iot/newsCategory")
|
||||
public class NewsCategoryController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private INewsCategoryService newsCategoryService;
|
||||
|
||||
/**
|
||||
* 查询新闻分类列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:newsCategory:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("新闻分类分页列表")
|
||||
public TableDataInfo list(NewsCategory newsCategory)
|
||||
{
|
||||
startPage();
|
||||
List<NewsCategory> list = newsCategoryService.selectNewsCategoryList(newsCategory);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询新闻分类简短列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:list')")
|
||||
@GetMapping("/newsCategoryShortList")
|
||||
@ApiOperation("分类简短列表")
|
||||
public AjaxResult newsCategoryShortList()
|
||||
{
|
||||
List<IdAndName> list = newsCategoryService.selectNewsCategoryShortList();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出新闻分类列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:newsCategory:export')")
|
||||
@Log(title = "新闻分类", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, NewsCategory newsCategory)
|
||||
{
|
||||
List<NewsCategory> list = newsCategoryService.selectNewsCategoryList(newsCategory);
|
||||
ExcelUtil<NewsCategory> util = new ExcelUtil<NewsCategory>(NewsCategory.class);
|
||||
util.exportExcel(response, list, "新闻分类数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新闻分类详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:newsCategory:query')")
|
||||
@GetMapping(value = "/{categoryId}")
|
||||
@ApiOperation("新闻分类详情")
|
||||
public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
|
||||
{
|
||||
return AjaxResult.success(newsCategoryService.selectNewsCategoryByCategoryId(categoryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增新闻分类
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:newsCategory:add')")
|
||||
@Log(title = "新闻分类", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加新闻分类")
|
||||
public AjaxResult add(@RequestBody NewsCategory newsCategory)
|
||||
{
|
||||
return toAjax(newsCategoryService.insertNewsCategory(newsCategory));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改新闻分类
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:newsCategory:edit')")
|
||||
@Log(title = "新闻分类", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改新闻分类")
|
||||
public AjaxResult edit(@RequestBody NewsCategory newsCategory)
|
||||
{
|
||||
return toAjax(newsCategoryService.updateNewsCategory(newsCategory));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除新闻分类
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:newsCategory:remove')")
|
||||
@Log(title = "新闻分类", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{categoryIds}")
|
||||
@ApiOperation("删除新闻分类")
|
||||
public AjaxResult remove(@PathVariable Long[] categoryIds)
|
||||
{
|
||||
return newsCategoryService.deleteNewsCategoryByCategoryIds(categoryIds);
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.model.CategoryNews;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.News;
|
||||
import com.fastbee.iot.service.INewsService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 新闻资讯Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-04-09
|
||||
*/
|
||||
@Api(tags = "新闻资讯")
|
||||
@RestController
|
||||
@RequestMapping("/iot/news")
|
||||
public class NewsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private INewsService newsService;
|
||||
|
||||
/**
|
||||
* 查询新闻资讯列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("新闻分页列表")
|
||||
public TableDataInfo list(News news)
|
||||
{
|
||||
startPage();
|
||||
List<News> list = newsService.selectNewsList(news);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询轮播的新闻资讯
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:list')")
|
||||
@GetMapping("/bannerList")
|
||||
@ApiOperation("轮播新闻列表")
|
||||
public AjaxResult bannerList()
|
||||
{
|
||||
News news=new News();
|
||||
news.setIsBanner(1);
|
||||
news.setStatus(1);
|
||||
List<News> list = newsService.selectNewsList(news);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询置顶的新闻资讯
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:list')")
|
||||
@GetMapping("/topList")
|
||||
@ApiOperation("置顶新闻列表")
|
||||
public AjaxResult topList()
|
||||
{
|
||||
List<CategoryNews> list = newsService.selectTopNewsList();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出新闻资讯列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:export')")
|
||||
@Log(title = "新闻资讯", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, News news)
|
||||
{
|
||||
List<News> list = newsService.selectNewsList(news);
|
||||
ExcelUtil<News> util = new ExcelUtil<News>(News.class);
|
||||
util.exportExcel(response, list, "新闻资讯数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新闻资讯详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:query')")
|
||||
@GetMapping(value = "/{newsId}")
|
||||
@ApiOperation("新闻详情")
|
||||
public AjaxResult getInfo(@PathVariable("newsId") Long newsId)
|
||||
{
|
||||
return AjaxResult.success(newsService.selectNewsByNewsId(newsId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增新闻资讯
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:add')")
|
||||
@Log(title = "新闻资讯", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加新闻资讯")
|
||||
public AjaxResult add(@RequestBody News news)
|
||||
{
|
||||
return toAjax(newsService.insertNews(news));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改新闻资讯
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:edit')")
|
||||
@Log(title = "新闻资讯", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改新闻资讯")
|
||||
public AjaxResult edit(@RequestBody News news)
|
||||
{
|
||||
return toAjax(newsService.updateNews(news));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除新闻资讯
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:news:remove')")
|
||||
@Log(title = "新闻资讯", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{newsIds}")
|
||||
@ApiOperation("删除新闻资讯")
|
||||
public AjaxResult remove(@PathVariable Long[] newsIds)
|
||||
{
|
||||
return toAjax(newsService.deleteNewsByNewsIds(newsIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.OrderControl;
|
||||
import com.fastbee.iot.service.IOrderControlService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 指令权限控制Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-07-01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/order/control")
|
||||
@Api(tags = "指令权限控制")
|
||||
public class OrderControlController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IOrderControlService orderControlService;
|
||||
|
||||
/**
|
||||
* 查询指令权限控制列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:control:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询指令权限控制列表")
|
||||
public TableDataInfo list(OrderControl orderControl)
|
||||
{
|
||||
startPage();
|
||||
List<OrderControl> list = orderControlService.selectOrderControlList(orderControl);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出指令权限控制列表
|
||||
*/
|
||||
@ApiOperation("导出指令权限控制列表")
|
||||
@PreAuthorize("@ss.hasPermi('order:control:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, OrderControl orderControl)
|
||||
{
|
||||
List<OrderControl> list = orderControlService.selectOrderControlList(orderControl);
|
||||
ExcelUtil<OrderControl> util = new ExcelUtil<OrderControl>(OrderControl.class);
|
||||
util.exportExcel(response, list, "指令权限控制数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指令权限控制详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:control:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取指令权限控制详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(orderControlService.selectOrderControlById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增指令权限控制
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:control:add')")
|
||||
@PostMapping
|
||||
@ApiOperation("新增指令权限控制")
|
||||
public AjaxResult add(@RequestBody OrderControl orderControl)
|
||||
{
|
||||
return toAjax(orderControlService.insertOrderControl(orderControl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改指令权限控制
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:control:edit')")
|
||||
@PutMapping
|
||||
@ApiOperation("修改指令权限控制")
|
||||
public AjaxResult edit(@RequestBody OrderControl orderControl)
|
||||
{
|
||||
return toAjax(orderControlService.updateOrderControl(orderControl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指令权限控制
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('order:control:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除指令权限控制")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(orderControlService.deleteOrderControlByIds(ids));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get")
|
||||
@ApiOperation("获取指令权限")
|
||||
public AjaxResult getControl(Long deviceId,Long modelId)
|
||||
{
|
||||
return orderControlService.judgeThingsModel(deviceId, modelId);
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.model.ProductAuthorizeVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.ProductAuthorize;
|
||||
import com.fastbee.iot.service.IProductAuthorizeService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 产品授权码Controller
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
@Api(tags = "产品授权码")
|
||||
@RestController
|
||||
@RequestMapping("/iot/authorize")
|
||||
public class ProductAuthorizeController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IProductAuthorizeService productAuthorizeService;
|
||||
|
||||
/**
|
||||
* 查询产品授权码列表
|
||||
*/
|
||||
@ApiOperation("查询产品授权码列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:query')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ProductAuthorize productAuthorize)
|
||||
{
|
||||
startPage();
|
||||
List<ProductAuthorize> list = productAuthorizeService.selectProductAuthorizeList(productAuthorize);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出产品授权码列表
|
||||
*/
|
||||
@ApiOperation("导出产品授权码列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:export')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ProductAuthorize productAuthorize)
|
||||
{
|
||||
List<ProductAuthorize> list = productAuthorizeService.selectProductAuthorizeList(productAuthorize);
|
||||
ExcelUtil<ProductAuthorize> util = new ExcelUtil<ProductAuthorize>(ProductAuthorize.class);
|
||||
util.exportExcel(response, list, "产品授权码数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品授权码详细信息
|
||||
*/
|
||||
@ApiOperation("获取产品授权码详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:query')")
|
||||
@GetMapping(value = "/{authorizeId}")
|
||||
public AjaxResult getInfo(@PathVariable("authorizeId") Long authorizeId)
|
||||
{
|
||||
return AjaxResult.success(productAuthorizeService.selectProductAuthorizeByAuthorizeId(authorizeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品授权码
|
||||
*/
|
||||
@ApiOperation("新增产品授权码")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:add')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ProductAuthorize productAuthorize)
|
||||
{
|
||||
return toAjax(productAuthorizeService.insertProductAuthorize(productAuthorize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数量批量新增产品授权码
|
||||
*/
|
||||
@ApiOperation("根据数量批量新增产品授权码")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:add')")
|
||||
@Log(title = "根据数量批量新增产品授权码", businessType = BusinessType.INSERT)
|
||||
@PostMapping("addProductAuthorizeByNum")
|
||||
public AjaxResult addProductAuthorizeByNum(@RequestBody ProductAuthorizeVO productAuthorizeVO)
|
||||
{
|
||||
return toAjax(productAuthorizeService.addProductAuthorizeByNum(productAuthorizeVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品授权码
|
||||
*/
|
||||
@ApiOperation("修改产品授权码")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:edit')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ProductAuthorize productAuthorize)
|
||||
{
|
||||
return toAjax(productAuthorizeService.updateProductAuthorize(productAuthorize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品授权码
|
||||
*/
|
||||
@ApiOperation("删除产品授权码")
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:remove')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{authorizeIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] authorizeIds)
|
||||
{
|
||||
return toAjax(productAuthorizeService.deleteProductAuthorizeByAuthorizeIds(authorizeIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,214 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.Product;
|
||||
import com.fastbee.iot.model.ChangeProductStatusModel;
|
||||
import com.fastbee.iot.model.IdAndName;
|
||||
import com.fastbee.iot.service.IProductService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.fastbee.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 产品Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "产品管理")
|
||||
@RestController
|
||||
@RequestMapping("/iot/product")
|
||||
public class ProductController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IProductService productService;
|
||||
|
||||
/**
|
||||
* 查询产品列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("产品分页列表")
|
||||
public TableDataInfo list(Product product)
|
||||
{
|
||||
startPage();
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (null == user.getDeptId()) {
|
||||
product.setTenantId(user.getUserId());
|
||||
return getDataTable(productService.selectTerminalUserProduct(product));
|
||||
}
|
||||
Boolean showSenior = product.getShowSenior();
|
||||
if (Objects.isNull(showSenior)){
|
||||
//默认展示上级产品
|
||||
product.setShowSenior(true);
|
||||
}
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
product.setAdmin(SecurityUtils.isAdmin(deptUserId));
|
||||
product.setDeptId(getLoginUser().getDeptId());
|
||||
product.setTenantId(deptUserId);
|
||||
return getDataTable(productService.selectProductList(product));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品简短列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:list')")
|
||||
@GetMapping("/shortList")
|
||||
@ApiOperation("产品简短列表")
|
||||
public AjaxResult shortList(Product product)
|
||||
{
|
||||
Boolean showSenior = product.getShowSenior();
|
||||
if (Objects.isNull(showSenior)){
|
||||
//默认展示上级产品
|
||||
product.setShowSenior(true);
|
||||
}
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
product.setAdmin(SecurityUtils.isAdmin(deptUserId));
|
||||
product.setDeptId(getLoginUser().getDeptId());
|
||||
product.setTenantId(deptUserId);
|
||||
startPage();
|
||||
List<IdAndName> list = productService.selectProductShortList(product);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出产品列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:export')")
|
||||
@Log(title = "产品", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出产品")
|
||||
public void export(HttpServletResponse response, Product product)
|
||||
{
|
||||
List<Product> list = productService.selectProductList(product);
|
||||
ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class);
|
||||
util.exportExcel(response, list, "产品数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:query')")
|
||||
@GetMapping(value = "/{productId}")
|
||||
@ApiOperation("获取产品详情")
|
||||
public AjaxResult getInfo(@PathVariable("productId") Long productId)
|
||||
{
|
||||
Product product = productService.selectProductByProductId(productId);
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
if (!Objects.equals(product.getTenantId(), deptUserId)){
|
||||
product.setIsOwner(0);
|
||||
}else {
|
||||
product.setIsOwner(1);
|
||||
}
|
||||
return AjaxResult.success(product);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:add')")
|
||||
@Log(title = "添加产品", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加产品")
|
||||
public AjaxResult add(@RequestBody Product product)
|
||||
{
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if (loginUser == null || loginUser.getUser() == null) {
|
||||
return error(MessageUtils.message("user.not.login"));
|
||||
}
|
||||
// 查询归属机构
|
||||
if (null != loginUser.getDeptId()) {
|
||||
product.setTenantId(loginUser.getUser().getDept().getDeptUserId());
|
||||
product.setTenantName(loginUser.getUser().getDept().getDeptUserName());
|
||||
} else {
|
||||
product.setTenantId(loginUser.getUser().getUserId());
|
||||
product.setTenantName(loginUser.getUser().getUserName());
|
||||
}
|
||||
return AjaxResult.success(productService.insertProduct(product));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:edit')")
|
||||
@Log(title = "修改产品", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改产品")
|
||||
public AjaxResult edit(@RequestBody Product product)
|
||||
{
|
||||
return toAjax(productService.updateProduct(product));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品下面的设备数量
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:query')")
|
||||
@GetMapping("/deviceCount/{productId}")
|
||||
@ApiOperation("获取产品下面的设备数量")
|
||||
public AjaxResult deviceCount(@PathVariable Long productId)
|
||||
{
|
||||
return AjaxResult.success(productService.selectDeviceCountByProductId(productId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布产品
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:add')")
|
||||
@Log(title = "更新产品状态", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/status")
|
||||
@ApiOperation("更新产品状态")
|
||||
public AjaxResult changeProductStatus(@RequestBody ChangeProductStatusModel model)
|
||||
{
|
||||
return productService.changeProductStatus(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:remove')")
|
||||
@Log(title = "产品", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{productIds}")
|
||||
@ApiOperation("批量删除产品")
|
||||
public AjaxResult remove(@PathVariable Long[] productIds)
|
||||
{
|
||||
return productService.deleteProductByProductIds(productIds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询采集点模板关联的所有产品
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:list')")
|
||||
@GetMapping("/queryByTemplateId")
|
||||
@ApiOperation("查询采集点模板id关联的所有产品")
|
||||
public AjaxResult queryByTemplateId(@RequestParam Long templateId){
|
||||
return AjaxResult.success(productService.selectByTempleId(templateId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品id查询Guid
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:product:query')")
|
||||
@GetMapping("/getGuid")
|
||||
@ApiOperation("根据产品id查询Guid")
|
||||
public AjaxResult getGuid(@RequestParam Long productId){
|
||||
return AjaxResult.success(productService.selectGuidByProductId(productId));
|
||||
}
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.Scene;
|
||||
import com.fastbee.iot.service.ISceneService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 场景联动Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-01-13
|
||||
*/
|
||||
@Api(tags = "场景联动")
|
||||
@RestController
|
||||
@RequestMapping("/iot/scene")
|
||||
public class SceneController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISceneService sceneService;
|
||||
|
||||
/**
|
||||
* 查询场景联动列表
|
||||
*/
|
||||
@ApiOperation("查询场景联动列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Scene scene)
|
||||
{
|
||||
startPage();
|
||||
List<Scene> list = sceneService.selectSceneList(scene);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出场景联动列表
|
||||
*/
|
||||
@ApiOperation("导出场景联动列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:export')")
|
||||
@Log(title = "场景联动", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Scene scene)
|
||||
{
|
||||
List<Scene> list = sceneService.selectSceneList(scene);
|
||||
ExcelUtil<Scene> util = new ExcelUtil<Scene>(Scene.class);
|
||||
util.exportExcel(response, list, "场景联动数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景联动详细信息
|
||||
*/
|
||||
@ApiOperation("获取场景联动详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:query')")
|
||||
@GetMapping(value = "/{sceneId}")
|
||||
public AjaxResult getInfo(@PathVariable("sceneId") Long sceneId)
|
||||
{
|
||||
return AjaxResult.success(sceneService.selectSceneBySceneId(sceneId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增场景联动
|
||||
*/
|
||||
@ApiOperation("新增场景联动")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:add')")
|
||||
@Log(title = "场景联动", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody Scene scene)
|
||||
{
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if (loginUser == null || loginUser.getUser() == null) {
|
||||
return error(MessageUtils.message("user.not.login"));
|
||||
}
|
||||
// 查询归属机构
|
||||
if (null != loginUser.getDeptId()) {
|
||||
scene.setUserId(loginUser.getUser().getDept().getDeptUserId());
|
||||
scene.setUserName(loginUser.getUser().getDept().getDeptUserName());
|
||||
scene.setTerminalUser(0);
|
||||
} else {
|
||||
scene.setUserId(loginUser.getUser().getUserId());
|
||||
scene.setUserName(loginUser.getUser().getUserName());
|
||||
scene.setTerminalUser(1);
|
||||
}
|
||||
return toAjax(sceneService.insertScene(scene));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景联动
|
||||
*/
|
||||
@ApiOperation("修改场景联动")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:edit')")
|
||||
@Log(title = "场景联动", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody Scene scene)
|
||||
{
|
||||
return toAjax(sceneService.updateScene(scene));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景联动
|
||||
*/
|
||||
@ApiOperation("删除场景联动")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:remove')")
|
||||
@Log(title = "场景联动", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{sceneIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] sceneIds)
|
||||
{
|
||||
return toAjax(sceneService.deleteSceneBySceneIds(sceneIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景联动状态
|
||||
*/
|
||||
@ApiOperation("修改场景联动状态")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:edit')")
|
||||
@Log(title = "场景联动", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/updateStatus")
|
||||
public AjaxResult updateStatus(@RequestBody Scene scene)
|
||||
{
|
||||
return toAjax(sceneService.updateStatus(scene));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:query')")
|
||||
@GetMapping(value = "/log/open/{chainName}")
|
||||
public AjaxResult openPublishLog(@PathVariable("chainName") String chainName)
|
||||
{
|
||||
sceneService.openSceneLog(chainName);
|
||||
return success();
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:query')")
|
||||
@GetMapping(value = "/log/close/{chainName}")
|
||||
public AjaxResult closePublishLog(@PathVariable("chainName") String chainName)
|
||||
{
|
||||
sceneService.closeSceneLog(chainName);
|
||||
return success();
|
||||
}
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.iot.domain.Script;
|
||||
import com.fastbee.iot.service.IScriptService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
import static com.fastbee.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 规则引擎脚本Controller
|
||||
*
|
||||
* @author lizhuangpeng
|
||||
* @date 2023-07-01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/script")
|
||||
public class ScriptController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IScriptService scriptService;
|
||||
|
||||
/**
|
||||
* 查询规则引擎脚本列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Script ruleScript)
|
||||
{
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
// List<SysRole> roles = sysUser.getRoles();
|
||||
// for (SysRole role : roles) {
|
||||
// if (role.getRoleKey().equals("general") || role.getRoleKey().equals("tenant")) {
|
||||
// // 用户和租户只能查看自己的规则脚本
|
||||
// ruleScript.setUserId(sysUser.getUserId());
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// 只能查看所属机构
|
||||
if (null != sysUser.getDeptId()) {
|
||||
ruleScript.setUserId(sysUser.getDept().getDeptUserId());
|
||||
} else {
|
||||
ruleScript.setUserId(sysUser.getUserId());
|
||||
}
|
||||
startPage();
|
||||
List<Script> list = scriptService.selectRuleScriptList(ruleScript);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出规则引擎脚本列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:export')")
|
||||
@Log(title = "规则引擎脚本", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Script ruleScript)
|
||||
{
|
||||
SysUser sysUser = getLoginUser().getUser();
|
||||
// List<SysRole> roles = sysUser.getRoles();
|
||||
// for (SysRole role : roles) {
|
||||
// if (role.getRoleKey().equals("general") || role.getRoleKey().equals("tenant")) {
|
||||
// // 用户和租户只能查看自己的规则脚本
|
||||
// ruleScript.setUserId(sysUser.getUserId());
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// 只能查看所属机构
|
||||
if (null != sysUser.getDeptId()) {
|
||||
ruleScript.setUserId(sysUser.getDept().getDeptUserId());
|
||||
} else {
|
||||
ruleScript.setUserId(sysUser.getUserId());
|
||||
}
|
||||
List<Script> list = scriptService.selectRuleScriptList(ruleScript);
|
||||
ExcelUtil<Script> util = new ExcelUtil<Script>(Script.class);
|
||||
util.exportExcel(response, list, "规则引擎脚本数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取规则引擎脚本详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:query')")
|
||||
@GetMapping(value = "/{scriptId}")
|
||||
public AjaxResult getInfo(@PathVariable("scriptId") String scriptId)
|
||||
{
|
||||
return success(scriptService.selectRuleScriptById(scriptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增规则引擎脚本
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:add')")
|
||||
@Log(title = "规则引擎脚本", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody Script ruleScript)
|
||||
{
|
||||
return toAjax(scriptService.insertRuleScript(ruleScript));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改规则引擎脚本
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:edit')")
|
||||
@Log(title = "规则引擎脚本", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody Script ruleScript)
|
||||
{
|
||||
return toAjax(scriptService.updateRuleScript(ruleScript));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取规则引擎脚本日志
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:query')")
|
||||
@GetMapping(value = "/log/{scriptId}")
|
||||
public AjaxResult getScriptLog(@PathVariable("scriptId") String scriptId)
|
||||
{
|
||||
return success(scriptService.selectRuleScriptLog(scriptId));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:query')")
|
||||
@GetMapping(value = "/log/open/{scriptId}")
|
||||
public AjaxResult openPublishLog(@PathVariable("scriptId") String scriptId)
|
||||
{
|
||||
scriptService.openScriptLog(scriptId);
|
||||
return success();
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:query')")
|
||||
@GetMapping(value = "/log/close/{scriptId}")
|
||||
public AjaxResult closePublishLog(@PathVariable("scriptId") String scriptId)
|
||||
{
|
||||
scriptService.closeScriptLog(scriptId);
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除规则引擎脚本
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:script:remove')")
|
||||
@Log(title = "规则引擎脚本", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{scriptIds}")
|
||||
public AjaxResult remove(@PathVariable String[] scriptIds)
|
||||
{
|
||||
return toAjax(scriptService.deleteRuleScriptByIds(scriptIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除规则引擎脚本
|
||||
*/
|
||||
@PostMapping("/validate")
|
||||
public AjaxResult validateScript(@RequestBody Script ruleScript)
|
||||
{
|
||||
return scriptService.validateScript(ruleScript);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.mq.message.MqttBo;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.SimulateLog;
|
||||
import com.fastbee.iot.service.ISimulateLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模拟设备日志Controller
|
||||
* @author gsb
|
||||
* @date 2023/4/6 17:06
|
||||
*/
|
||||
@Api(tags = "模拟设备日志")
|
||||
@RestController
|
||||
@RequestMapping("/iot/simulate")
|
||||
public class SimulateLogController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ISimulateLogService simulateLogService;
|
||||
|
||||
/**
|
||||
* 查询模拟设备日志列表
|
||||
*/
|
||||
@ApiOperation("查询模拟设备日志列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:simulate:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SimulateLog simulateLog) {
|
||||
startPage();
|
||||
List<MqttBo> list = simulateLogService.selectSimulateLogList(simulateLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模拟设备日志详细信息
|
||||
*/
|
||||
@ApiOperation("获取模拟设备日志详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:simulate:query')")
|
||||
@GetMapping(value = "/{logId}")
|
||||
public AjaxResult getInfo(@PathVariable("logId") Long logId) {
|
||||
return success(simulateLogService.selectSimulateLogByLogId(logId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增模拟设备日志
|
||||
*/
|
||||
@ApiOperation("新增模拟设备日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:simulate:add')")
|
||||
@Log(title = "模拟设备日志", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SimulateLog simulateLog) {
|
||||
return toAjax(simulateLogService.insertSimulateLog(simulateLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改模拟设备日志
|
||||
*/
|
||||
@ApiOperation("修改模拟设备日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:simulate:edit')")
|
||||
@Log(title = "模拟设备日志", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SimulateLog simulateLog) {
|
||||
return toAjax(simulateLogService.updateSimulateLog(simulateLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模拟设备日志
|
||||
*/
|
||||
@ApiOperation("删除模拟设备日志")
|
||||
@PreAuthorize("@ss.hasPermi('iot:simulate:remove')")
|
||||
@Log(title = "模拟设备日志", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{logIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] logIds) {
|
||||
return toAjax(simulateLogService.deleteSimulateLogByLogIds(logIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.iot.domain.SipRelation;
|
||||
import com.fastbee.iot.service.ISipRelationService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 监控设备关联Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/relation")
|
||||
@Api(tags = "监控设备关联")
|
||||
public class SipRelationController extends BaseController {
|
||||
@Autowired
|
||||
private ISipRelationService sipRelationService;
|
||||
|
||||
/**
|
||||
* 查询监控设备关联列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询监控设备关联列表")
|
||||
public TableDataInfo list(SipRelation sipRelation) {
|
||||
startPage();
|
||||
List<SipRelation> list = sipRelationService.selectSipRelationList(sipRelation);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出监控设备关联列表
|
||||
*/
|
||||
@ApiOperation("导出监控设备关联列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SipRelation sipRelation) {
|
||||
List<SipRelation> list = sipRelationService.selectSipRelationList(sipRelation);
|
||||
ExcelUtil<SipRelation> util = new ExcelUtil<SipRelation>(SipRelation.class);
|
||||
util.exportExcel(response, list, "监控设备关联数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控设备关联详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取监控设备关联详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return success(sipRelationService.selectSipRelationById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:query')")
|
||||
@GetMapping(value = "/dev/{deviceId}")
|
||||
@ApiOperation("根据设备id获取关联通道详细信息")
|
||||
public AjaxResult getInfoByDeviceId(@PathVariable("deviceId") Long deviceId) {
|
||||
return success(sipRelationService.selectSipRelationByDeviceId(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或更新监控设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:add')")
|
||||
@PostMapping("/addOrUp")
|
||||
@ApiOperation("新增或更新监控设备关联")
|
||||
public AjaxResult addOrUp(@RequestBody SipRelation sipRelation) {
|
||||
return toAjax(sipRelationService.addOrUpdateSipRelation(sipRelation));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改监控设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:edit')")
|
||||
@PutMapping
|
||||
@ApiOperation("修改监控设备关联")
|
||||
public AjaxResult edit(@RequestBody SipRelation sipRelation) {
|
||||
return toAjax(sipRelationService.updateSipRelation(sipRelation));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监控设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:relation:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除监控设备关联")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(sipRelationService.deleteSipRelationByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.model.BindLoginBody;
|
||||
import com.fastbee.common.core.domain.model.BindRegisterBody;
|
||||
import com.fastbee.common.core.domain.model.LoginBody;
|
||||
import com.fastbee.iot.service.ISocialLoginService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.fastbee.common.constant.Constants.LANGUAGE;
|
||||
|
||||
/**
|
||||
* 第三方登录接口Controller
|
||||
*
|
||||
* @author json
|
||||
* @date 2022-04-12
|
||||
*/
|
||||
@Api(tags = "第三方登录接口")
|
||||
@RestController
|
||||
@RequestMapping("/auth")
|
||||
public class SocialLoginController {
|
||||
|
||||
@Autowired
|
||||
private ISocialLoginService iSocialLoginService;
|
||||
|
||||
|
||||
@GetMapping("/render/{source}")
|
||||
@ApiOperation("微信登录跳转二维码")
|
||||
@ApiImplicitParam(name = "source", value = "登录类型", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public void renderAuth(HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest, @PathVariable String source) throws IOException {
|
||||
// 生成授权页面
|
||||
httpServletResponse.sendRedirect(iSocialLoginService.renderAuth(source, httpServletRequest));
|
||||
}
|
||||
|
||||
@GetMapping("/callback/{source}")
|
||||
@ApiOperation("微信登录扫码回调api")
|
||||
@ApiImplicitParam(name = "source", value = "平台来源", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public void login(@PathVariable("source") String source, AuthCallback authCallback, HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest) throws IOException {
|
||||
//回调接口
|
||||
httpServletResponse.sendRedirect(iSocialLoginService.callback(source, authCallback, httpServletRequest));
|
||||
}
|
||||
|
||||
@GetMapping("/checkBindId/{bindId}")
|
||||
@ApiOperation("检查bindId")
|
||||
@ApiImplicitParam(name = "bindId", value = "绑定ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult checkBindId(@PathVariable String bindId) {
|
||||
return iSocialLoginService.checkBindId(bindId);
|
||||
}
|
||||
|
||||
@GetMapping("/getErrorMsg/{errorId}")
|
||||
@ApiOperation("获取errorMsg")
|
||||
@ApiImplicitParam(name = "errorId", value = "错误提示ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult getErrorMsg(@PathVariable String errorId) {
|
||||
return iSocialLoginService.getErrorMsg(errorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已经绑定账户,跳转登录接口
|
||||
*
|
||||
* @param loginId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/login/{loginId}")
|
||||
@ApiOperation("跳转登录api")
|
||||
@ApiImplicitParam(name = "loginId", value = "登录Id", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult socialLogin(HttpServletRequest request, @PathVariable String loginId) {
|
||||
// 生成授权页面
|
||||
return iSocialLoginService.socialLogin(loginId, request.getHeader(LANGUAGE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
* @param bindLoginBody 绑定登录信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation("绑定登录方法")
|
||||
@PostMapping("/bind/login")
|
||||
public AjaxResult bindLogin(HttpServletRequest request, @RequestBody BindLoginBody bindLoginBody) {
|
||||
return iSocialLoginService.bindLogin(bindLoginBody, request.getHeader(LANGUAGE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册绑定接口
|
||||
*
|
||||
* @param bindRegisterBody 注册信息
|
||||
* @return 注册绑定信息
|
||||
*/
|
||||
@ApiOperation("注册绑定")
|
||||
@PostMapping("/bind/register")
|
||||
public AjaxResult bindRegister(HttpServletRequest request, @RequestBody BindRegisterBody bindRegisterBody) {
|
||||
return iSocialLoginService.bindRegister(bindRegisterBody, request.getHeader(LANGUAGE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信登录方法
|
||||
*
|
||||
* @param loginBody 登录信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation("短信登录")
|
||||
@PostMapping("/sms/login")
|
||||
public AjaxResult smsLogin(HttpServletRequest request, @RequestBody LoginBody loginBody) {
|
||||
return iSocialLoginService.smsLogin(loginBody, request.getHeader(LANGUAGE));
|
||||
}
|
||||
|
||||
/**
|
||||
* oauth2登录
|
||||
* @param loginBody 登录信息
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@ApiOperation("登录")
|
||||
@PostMapping("/ssoLogin")
|
||||
public AjaxResult ssoLogin(HttpServletRequest request, @RequestBody LoginBody loginBody) {
|
||||
return iSocialLoginService.ssoLogin(loginBody, request.getHeader(LANGUAGE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,109 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.SocialPlatform;
|
||||
import com.fastbee.iot.service.ISocialPlatformService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 第三方登录平台控制Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
@Api(tags = "第三方登录平台")
|
||||
@RestController
|
||||
@RequestMapping("/iot/platform")
|
||||
public class SocialPlatformController extends BaseController {
|
||||
@Autowired
|
||||
private ISocialPlatformService socialPlatformService;
|
||||
|
||||
/**
|
||||
* 查询第三方登录平台控制列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:platform:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("第三方登录平台分页列表")
|
||||
public TableDataInfo list(SocialPlatform socialPlatform) {
|
||||
startPage();
|
||||
List<SocialPlatform> list = socialPlatformService.selectSocialPlatformList(socialPlatform);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出第三方登录平台控制列表
|
||||
*/
|
||||
@ApiOperation("导出第三方登录平台控制列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:platform:export')")
|
||||
@Log(title = "第三方登录平台控制", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SocialPlatform socialPlatform) {
|
||||
List<SocialPlatform> list = socialPlatformService.selectSocialPlatformList(socialPlatform);
|
||||
ExcelUtil<SocialPlatform> util = new ExcelUtil<SocialPlatform>(SocialPlatform.class);
|
||||
util.exportExcel(response, list, "第三方登录平台控制数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第三方登录平台控制详细信息
|
||||
*/
|
||||
@ApiOperation("获取第三方登录平台控制详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:platform:query')")
|
||||
@GetMapping(value = "/{socialPlatformId}")
|
||||
public AjaxResult getInfo(@PathVariable("socialPlatformId") Long socialPlatformId) {
|
||||
return AjaxResult.success(socialPlatformService.selectSocialPlatformBySocialPlatformId(socialPlatformId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增第三方登录平台控制
|
||||
*/
|
||||
@ApiOperation("新增第三方登录平台控制")
|
||||
@PreAuthorize("@ss.hasPermi('iot:platform:add')")
|
||||
@Log(title = "第三方登录平台控制", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SocialPlatform socialPlatform) {
|
||||
socialPlatform.setCreateBy(getUsername());
|
||||
return toAjax(socialPlatformService.insertSocialPlatform(socialPlatform));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改第三方登录平台控制
|
||||
*/
|
||||
@ApiOperation("修改第三方登录平台控制")
|
||||
@PreAuthorize("@ss.hasPermi('iot:platform:edit')")
|
||||
@Log(title = "第三方登录平台控制", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SocialPlatform socialPlatform) {
|
||||
socialPlatform.setUpdateBy(getUsername());
|
||||
return toAjax(socialPlatformService.updateSocialPlatform(socialPlatform));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除第三方登录平台控制
|
||||
*/
|
||||
@ApiOperation("删除第三方登录平台控制")
|
||||
@PreAuthorize("@ss.hasPermi('iot:platform:remove')")
|
||||
@Log(title = "第三方登录平台控制", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{socialPlatformIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] socialPlatformIds) {
|
||||
return toAjax(socialPlatformService.deleteSocialPlatformBySocialPlatformIds(socialPlatformIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.iot.ruleEngine.MsgContext;
|
||||
import com.fastbee.ruleEngine.core.FlowLogExecutor;
|
||||
import com.fastbee.ruleEngine.core.RequestIdBuilder;
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class TestRuleController {
|
||||
|
||||
@Autowired
|
||||
private FlowLogExecutor flowExecutorlog;
|
||||
|
||||
@GetMapping("/testrule")
|
||||
public void test(@RequestParam String id) {
|
||||
MsgContext context = MsgContext.builder()
|
||||
.topic("topic")
|
||||
.payload("payload")
|
||||
.serialNumber("serialNumber")
|
||||
.productId(111L)
|
||||
.protocolCode("ProtocolCode")
|
||||
.build();
|
||||
DefaultContext dcxt = new DefaultContext();
|
||||
LiteFlowChainELBuilder.createChain().setChainName("dataChain").setEL("THEN(" + id + ",httpBridge)").build();
|
||||
// 执行规则脚本
|
||||
LiteflowResponse response = flowExecutorlog.execute2Resp("dataChain", null, context, dcxt);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("规则脚本执行发生错误:" + response.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/testrule1")
|
||||
public void test1(@RequestParam String ifid, @RequestParam String id) {
|
||||
MsgContext context = MsgContext.builder()
|
||||
.topic("topic")
|
||||
.payload("payload")
|
||||
.serialNumber("serialNumber")
|
||||
.productId(111L)
|
||||
.protocolCode("ProtocolCode")
|
||||
.build();
|
||||
DefaultContext dcxt = new DefaultContext();
|
||||
LiteFlowChainELBuilder.createChain().setChainName("dataChain").setEL("IF(" + ifid + "," + id +")").build();
|
||||
String Rid = RequestIdBuilder.buildProductRequestId(context.getProductId(),context.getSerialNumber());
|
||||
// 执行规则脚本
|
||||
LiteflowResponse response = flowExecutorlog.execute2RespWithRid("dataChain", null, Rid, context, dcxt);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("规则脚本执行发生错误:" + response.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,205 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.cache.ITSLCache;
|
||||
import com.fastbee.iot.domain.ThingsModel;
|
||||
import com.fastbee.iot.model.ImportThingsModelInput;
|
||||
import com.fastbee.iot.model.ThingsModelPerm;
|
||||
import com.fastbee.iot.model.modbus.ModbusAndThingsVO;
|
||||
import com.fastbee.iot.model.varTemp.SyncModel;
|
||||
import com.fastbee.iot.service.IThingsModelService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 物模型Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/model")
|
||||
@Api(tags="产品物模型")
|
||||
public class ThingsModelController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IThingsModelService thingsModelService;
|
||||
@Resource
|
||||
private ITSLCache itslCache;
|
||||
|
||||
/**
|
||||
* 查询物模型列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("产品物模型分页列表")
|
||||
public TableDataInfo list(ThingsModel thingsModel)
|
||||
{
|
||||
startPage();
|
||||
List<ThingsModel> list = thingsModelService.selectThingsModelList(thingsModel);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询物模型对应设备分享权限
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:device:list')")
|
||||
@GetMapping("/permList/{productId}")
|
||||
@ApiOperation("查询物模型对应设备分享权限")
|
||||
public AjaxResult permList(@PathVariable Long productId)
|
||||
{
|
||||
List<ThingsModelPerm> list = thingsModelService.selectThingsModelPermList(productId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物模型详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:query')")
|
||||
@GetMapping(value = "/{modelId}")
|
||||
@ApiOperation("获取产品物模型详情")
|
||||
public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
|
||||
{
|
||||
return AjaxResult.success(thingsModelService.selectThingsModelByModelId(modelId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:add')")
|
||||
@Log(title = "物模型", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加产品物模型")
|
||||
public AjaxResult add(@RequestBody ThingsModel thingsModel)
|
||||
{
|
||||
int result=thingsModelService.insertThingsModel(thingsModel);
|
||||
if(result==1){
|
||||
return AjaxResult.success();
|
||||
}else if(result==2){
|
||||
return AjaxResult.error(MessageUtils.message("things.model.identifier.repeat"));
|
||||
}else{
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:import')")
|
||||
@Log(title = "导入物模型",businessType = BusinessType.INSERT)
|
||||
@PostMapping("/import")
|
||||
@ApiOperation("导入通用物模型")
|
||||
public AjaxResult ImportByTemplateIds(@RequestBody ImportThingsModelInput input){
|
||||
int repeatCount=thingsModelService.importByTemplateIds(input);
|
||||
if(repeatCount==0){
|
||||
return AjaxResult.success(MessageUtils.message("import.success"));
|
||||
}else{
|
||||
return AjaxResult.success(StringUtils.format(MessageUtils.message("things.model.import.failed.identifier.repeat"), repeatCount));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:edit')")
|
||||
@Log(title = "物模型", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改产品物模型")
|
||||
public AjaxResult edit(@RequestBody ThingsModel thingsModel)
|
||||
{
|
||||
int result=thingsModelService.updateThingsModel(thingsModel);
|
||||
if(result==1){
|
||||
return AjaxResult.success();
|
||||
}else if(result==2){
|
||||
return AjaxResult.error(MessageUtils.message("things.model.identifier.repeat"));
|
||||
}else{
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:remove')")
|
||||
@Log(title = "物模型", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{modelIds}")
|
||||
@ApiOperation("批量删除产品物模型")
|
||||
public AjaxResult remove(@PathVariable Long[] modelIds)
|
||||
{
|
||||
return toAjax(thingsModelService.deleteThingsModelByModelIds(modelIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的JSON物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:query')")
|
||||
@GetMapping(value = "/cache/{productId}")
|
||||
@ApiOperation("获取缓存的JSON物模型")
|
||||
public AjaxResult getCacheThingsModelByProductId(@PathVariable("productId") Long productId)
|
||||
{
|
||||
return AjaxResult.success(MessageUtils.message("operate.success"),itslCache.getCacheThingsModelByProductId(productId));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "物模型导入模板")
|
||||
@PostMapping("/temp")
|
||||
public void temp(HttpServletResponse response){
|
||||
ExcelUtil<ThingsModel> excelUtil = new ExcelUtil<>(ThingsModel.class);
|
||||
excelUtil.importTemplateExcel(response,"采集点");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导入采集点
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:point:import')")
|
||||
@ApiOperation(value = "采集点导入")
|
||||
@PostMapping(value = "/importData")
|
||||
public AjaxResult importData(MultipartFile file,Long productId) throws Exception{
|
||||
ExcelUtil<ThingsModel> excelUtil = new ExcelUtil<>(ThingsModel.class);
|
||||
List<ThingsModel> list = excelUtil.importExcel(file.getInputStream());
|
||||
String result = thingsModelService.importData(list, productId);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取modbus配置可选择物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:list')")
|
||||
@GetMapping("/listModbus")
|
||||
@ApiOperation("获取modbus配置可选择物模型")
|
||||
public TableDataInfo listModbus(Long productId)
|
||||
{
|
||||
startPage();
|
||||
List<ModbusAndThingsVO> list = thingsModelService.getModbusConfigUnSelectThingsModel(productId);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据设备获取可读写物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:model:list')")
|
||||
@GetMapping("/write")
|
||||
@ApiOperation("根据设备获取可读写物模型")
|
||||
public TableDataInfo write(Long deviceId)
|
||||
{
|
||||
startPage();
|
||||
List<ThingsModel> thingsModelList = thingsModelService.selectThingsModelBySerialNumber(deviceId);
|
||||
return getDataTable(thingsModelList);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.iot.domain.ThingsModelJsonTemplate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.ThingsModelTemplate;
|
||||
import com.fastbee.iot.service.IThingsModelTemplateService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import static com.fastbee.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 通用物模型Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/template")
|
||||
@Api(tags = "通用物模型")
|
||||
public class ThingsModelTemplateController extends BaseController {
|
||||
@Autowired
|
||||
private IThingsModelTemplateService thingsModelTemplateService;
|
||||
|
||||
/**
|
||||
* 查询通用物模型列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("通用物模型分页列表")
|
||||
public TableDataInfo list(ThingsModelTemplate thingsModelTemplate) {
|
||||
startPage();
|
||||
return getDataTable(thingsModelTemplateService.selectThingsModelTemplateList(thingsModelTemplate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出通用物模型列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:export')")
|
||||
@Log(title = "通用物模型", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出通用物模型")
|
||||
public void export(HttpServletResponse response, ThingsModelTemplate thingsModelTemplate) {
|
||||
List<ThingsModelTemplate> list = thingsModelTemplateService.selectThingsModelTemplateList(thingsModelTemplate);
|
||||
ExcelUtil<ThingsModelTemplate> util = new ExcelUtil<ThingsModelTemplate>(ThingsModelTemplate.class);
|
||||
util.exportExcel(response, list, "通用物模型数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通用物模型详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:query')")
|
||||
@GetMapping(value = "/{templateId}")
|
||||
@ApiOperation("获取通用物模型详情")
|
||||
public AjaxResult getInfo(@PathVariable("templateId") Long templateId) {
|
||||
return AjaxResult.success(thingsModelTemplateService.selectThingsModelTemplateByTemplateId(templateId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增通用物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:add')")
|
||||
@Log(title = "通用物模型", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("添加通用物模型")
|
||||
public AjaxResult add(@RequestBody ThingsModelTemplate thingsModelTemplate) {
|
||||
return toAjax(thingsModelTemplateService.insertThingsModelTemplate(thingsModelTemplate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改通用物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:edit')")
|
||||
@Log(title = "通用物模型", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改通用物模型")
|
||||
public AjaxResult edit(@RequestBody ThingsModelTemplate thingsModelTemplate) {
|
||||
return toAjax(thingsModelTemplateService.updateThingsModelTemplate(thingsModelTemplate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除通用物模型
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:remove')")
|
||||
@Log(title = "通用物模型", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{templateIds}")
|
||||
@ApiOperation("批量删除通用物模型")
|
||||
public AjaxResult remove(@PathVariable Long[] templateIds) {
|
||||
return toAjax(thingsModelTemplateService.deleteThingsModelTemplateByTemplateIds(templateIds));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "物模型导入模板")
|
||||
@PostMapping("/temp")
|
||||
public void temp(HttpServletResponse response) {
|
||||
ExcelUtil<ThingsModelTemplate> excelUtil = new ExcelUtil<>(ThingsModelTemplate.class);
|
||||
excelUtil.importTemplateExcel(response, "采集点");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "物模型导入模板")
|
||||
@RequestMapping(value = "/temp-json",method = RequestMethod.POST)
|
||||
public void tempJson(HttpServletResponse response) {
|
||||
ExcelUtil<ThingsModelJsonTemplate> excelUtil = new ExcelUtil<>(ThingsModelJsonTemplate.class);
|
||||
excelUtil.importTemplateExcel(response, "JSON采集点模板");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导入采集点
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:add')")
|
||||
@ApiOperation(value = "采集点导入")
|
||||
@PostMapping(value = "/importData")
|
||||
public AjaxResult importData(MultipartFile file, String tempSlaveId) throws Exception {
|
||||
ExcelUtil<ThingsModelTemplate> excelUtil = new ExcelUtil<>(ThingsModelTemplate.class);
|
||||
List<ThingsModelTemplate> list = excelUtil.importExcel(file.getInputStream());
|
||||
String result = thingsModelTemplateService.importData(list, tempSlaveId);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
@ApiOperation("导出采集点")
|
||||
@PreAuthorize("@ss.hasPermi('iot:template:query')")
|
||||
@PostMapping("/exportJson")
|
||||
public void exportJson(HttpServletResponse response, ThingsModelTemplate template)
|
||||
{
|
||||
List<ThingsModelTemplate> thingsModelTemplates = thingsModelTemplateService.selectThingsModelTemplateExport(template);
|
||||
ExcelUtil<ThingsModelTemplate> util = new ExcelUtil<ThingsModelTemplate>(ThingsModelTemplate.class);
|
||||
util.exportExcel(response, thingsModelTemplates, "采集点");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,504 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.dtflys.forest.Forest;
|
||||
import com.dtflys.forest.http.ForestRequest;
|
||||
import com.dtflys.forest.http.ForestRequestType;
|
||||
import com.dtflys.forest.http.ForestResponse;
|
||||
import com.fastbee.common.ProtocolDeCodeService;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.config.RuoYiConfig;
|
||||
import com.fastbee.common.constant.Constants;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.entity.SysUser;
|
||||
import com.fastbee.common.core.iot.response.DeCodeBo;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.core.protocol.modbus.ModbusCode;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.enums.DeviceStatus;
|
||||
import com.fastbee.common.exception.file.FileNameLengthLimitExceededException;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.file.FileUploadUtils;
|
||||
import com.fastbee.common.utils.file.FileUtils;
|
||||
import com.fastbee.common.utils.gateway.mq.TopicsUtils;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.model.*;
|
||||
import com.fastbee.iot.model.ThingsModels.ThingsModelShadow;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import com.fastbee.iot.service.IToolService;
|
||||
import com.fastbee.iot.util.VelocityInitializer;
|
||||
import com.fastbee.iot.util.VelocityUtils;
|
||||
import com.fastbee.mq.model.ReportDataBo;
|
||||
import com.fastbee.mq.service.IMqttMessagePublish;
|
||||
import com.fastbee.mq.service.IRuleEngine;
|
||||
import com.fastbee.mqtt.model.PushMessageBo;
|
||||
import com.fastbee.mqttclient.MqttClientConfig;
|
||||
import com.fastbee.mqttclient.PubMqttClient;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import okhttp3.Credentials;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static com.fastbee.common.utils.file.FileUploadUtils.getExtension;
|
||||
|
||||
/**
|
||||
* 产品分类Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "工具相关")
|
||||
@RestController
|
||||
@RequestMapping("/iot/tool")
|
||||
public class ToolController extends BaseController {
|
||||
private static final Logger log = LoggerFactory.getLogger(ToolController.class);
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
@Autowired
|
||||
private IMqttMessagePublish messagePublish;
|
||||
@Autowired
|
||||
private MqttClientConfig mqttConfig;
|
||||
@Autowired
|
||||
private IToolService toolService;
|
||||
// 令牌秘钥
|
||||
@Value("${token.secret}")
|
||||
private String secret;
|
||||
@Resource
|
||||
private IRuleEngine ruleEngine;
|
||||
@Resource
|
||||
private ProtocolDeCodeService deCodeService;
|
||||
@Resource
|
||||
private PubMqttClient mqttClient;
|
||||
|
||||
@Autowired
|
||||
private EmqxApiConfig emqxApiConfig;
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
@ApiOperation("用户注册")
|
||||
@PostMapping("/register")
|
||||
public AjaxResult register(@RequestBody RegisterUserInput user) {
|
||||
String msg = toolService.register(user);
|
||||
return StringUtils.isEmpty(msg) ? success() : error(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
@ApiOperation("获取用户列表")
|
||||
@GetMapping("/userList")
|
||||
public TableDataInfo list(SysUser user)
|
||||
{
|
||||
startPage();
|
||||
List<SysUser> list = toolService.selectUserList(user);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@ApiOperation("mqtt认证")
|
||||
@PostMapping("/mqtt/auth")
|
||||
public ResponseEntity mqttAuth(@RequestParam String clientid, @RequestParam String username, @RequestParam String password) throws Exception {
|
||||
if (clientid.startsWith("server")) {
|
||||
// 服务端认证:配置的账号密码认证
|
||||
if (mqttConfig.getUsername().equals(username) && mqttConfig.getPassword().equals(password)) {
|
||||
log.info("-----------服务端mqtt认证成功,clientId:" + clientid + "---------------");
|
||||
return ResponseEntity.ok().body("ok");
|
||||
} else {
|
||||
return toolService.returnUnauthorized(new MqttAuthenticationModel(clientid, username, password), MessageUtils.message("mqtt.unauthorized"));
|
||||
}
|
||||
} else if (clientid.startsWith("web") || clientid.startsWith("phone")) {
|
||||
// web端和移动端认证:token认证
|
||||
String token = password;
|
||||
if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) {
|
||||
token = token.replace(Constants.TOKEN_PREFIX, "");
|
||||
}
|
||||
try {
|
||||
Claims claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||
log.info("-----------移动端/Web端mqtt认证成功,clientId:" + clientid + "---------------");
|
||||
return ResponseEntity.ok().body("ok");
|
||||
} catch (Exception ex) {
|
||||
return toolService.returnUnauthorized(new MqttAuthenticationModel(clientid, username, password), ex.getMessage());
|
||||
}
|
||||
} else {
|
||||
// 替换为整合之后的接口
|
||||
return toolService.clientAuth(clientid, username, password);
|
||||
}
|
||||
}
|
||||
@ApiOperation("mqtt认证")
|
||||
@PostMapping("/mqtt/authv5")
|
||||
public ResponseEntity mqttAuthv5(@RequestBody JSONObject json) throws Exception {
|
||||
log.info("-----------auth-json:" + json + "---------------");
|
||||
String clientid = json.getString("clientid");
|
||||
String username = json.getString("username");
|
||||
String password = json.getString("password");
|
||||
String peerhost = json.getString("peerhost"); // 源IP地址
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("is_superuser", false);
|
||||
if (clientid.startsWith("server")) {
|
||||
// 服务端认证:配置的账号密码认证
|
||||
if (mqttConfig.getUsername().equals(username) && mqttConfig.getPassword().equals(password)) {
|
||||
log.info("-----------服务端mqtt认证成功,clientId:" + clientid + "---------------");
|
||||
ret.put("result", "allow");
|
||||
return ResponseEntity.ok().body(ret);
|
||||
} else {
|
||||
ret.put("result", "deny");
|
||||
return ResponseEntity.ok().body(ret);
|
||||
}
|
||||
} else if (clientid.startsWith("web") || clientid.startsWith("phone")) {
|
||||
// web端和移动端认证:token认证
|
||||
String token = password;
|
||||
if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) {
|
||||
token = token.replace(Constants.TOKEN_PREFIX, "");
|
||||
}
|
||||
try {
|
||||
Claims claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
||||
log.info("-----------移动端/Web端mqtt认证成功,clientId:" + clientid + "---------------");
|
||||
ret.put("result", "allow");
|
||||
return ResponseEntity.ok().body(ret);
|
||||
} catch (Exception ex) {
|
||||
ret.put("result", "deny");
|
||||
return ResponseEntity.ok().body(ret);
|
||||
}
|
||||
} else {
|
||||
// 替换为整合之后的接口
|
||||
return toolService.clientAuthv5(clientid, username, password);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("mqtt钩子处理")
|
||||
@PostMapping("/mqtt/webhook")
|
||||
public void webHookProcess(@RequestBody MqttClientConnectModel model) {
|
||||
try {
|
||||
System.out.println("webhook:" + model.getAction());
|
||||
// 过滤服务端、web端和手机端
|
||||
if (model.getClientid().startsWith("server") || model.getClientid().startsWith("web") || model.getClientid().startsWith("phone")) {
|
||||
return;
|
||||
}
|
||||
// 设备端认证:加密认证(E)和简单认证(S,配置的账号密码认证)
|
||||
String[] clientArray = model.getClientid().split("&");
|
||||
String authType = clientArray[0];
|
||||
String deviceNumber = clientArray[1];
|
||||
Long productId = Long.valueOf(clientArray[2]);
|
||||
Long userId = Long.valueOf(clientArray[3]);
|
||||
|
||||
Device device = deviceService.selectShortDeviceBySerialNumber(deviceNumber);
|
||||
ReportDataBo ruleBo = new ReportDataBo();
|
||||
ruleBo.setProductId(device.getProductId());
|
||||
ruleBo.setSerialNumber(device.getSerialNumber());
|
||||
// 设备状态(1-未激活,2-禁用,3-在线,4-离线)
|
||||
if (model.getAction().equals("client_disconnected")) {
|
||||
device.setStatus(4);
|
||||
deviceService.updateDeviceStatusAndLocation(device, "");
|
||||
// 设备掉线后发布设备状态
|
||||
messagePublish.publishStatus(device.getProductId(), device.getSerialNumber(), 4, device.getIsShadow(),device.getRssi());
|
||||
// 清空保留消息,上线后发布新的属性功能保留消息
|
||||
messagePublish.publishProperty(device.getProductId(), device.getSerialNumber(), null,0);
|
||||
messagePublish.publishFunction(device.getProductId(), device.getSerialNumber(), null,0);
|
||||
// 规则匹配处理(告警和场景联动)
|
||||
ruleBo.setType(6);
|
||||
ruleEngine.ruleMatch(ruleBo);
|
||||
} else if (model.getAction().equals("client_connected")) {
|
||||
device.setStatus(3);
|
||||
deviceService.updateDeviceStatusAndLocation(device, model.getIpaddress());
|
||||
// 设备上线后发布设备状态
|
||||
messagePublish.publishStatus(device.getProductId(), device.getSerialNumber(), 3, device.getIsShadow(),device.getRssi());
|
||||
// 影子模式,发布属性和功能
|
||||
if (device.getIsShadow() == 1) {
|
||||
ThingsModelShadow shadow = deviceService.getDeviceShadowThingsModel(device);
|
||||
if (shadow.getProperties().size() > 0) {
|
||||
messagePublish.publishProperty(device.getProductId(), device.getSerialNumber(), shadow.getProperties(),3);
|
||||
}
|
||||
if (shadow.getFunctions().size() > 0) {
|
||||
messagePublish.publishFunction(device.getProductId(), device.getSerialNumber(), shadow.getFunctions(),3);
|
||||
}
|
||||
}
|
||||
// 规则匹配处理(告警和场景联动)
|
||||
ruleBo.setType(5);
|
||||
ruleEngine.ruleMatch(ruleBo);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
log.error("发生错误:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("mqtt钩子处理")
|
||||
@PostMapping("/mqtt/webhookv5")
|
||||
public void webHookProcessv5(@RequestBody JSONObject json) {
|
||||
try {
|
||||
String clientid = json.getString("clientid");
|
||||
String event = json.getString("event");
|
||||
String peername = json.getString("peername"); // 类似 127.0.0.1:8812
|
||||
String ipAddress = peername;
|
||||
if(peername.indexOf(":")!=-1){
|
||||
ipAddress = peername.substring(0,peername.indexOf(":"));
|
||||
}
|
||||
log.info("webhook:" + event + ",clientid:" + clientid);
|
||||
// 过滤服务端、web端和手机端
|
||||
if (clientid.startsWith("server") || clientid.startsWith("web") || clientid.startsWith("phone")) {
|
||||
return;
|
||||
}
|
||||
// 设备端认证:加密认证(E)和简单认证(S,配置的账号密码认证)
|
||||
String[] clientArray = clientid.split("&");
|
||||
String deviceNumber = clientArray[1];
|
||||
|
||||
Device device = deviceService.selectShortDeviceBySerialNumber(deviceNumber);
|
||||
ReportDataBo ruleBo = new ReportDataBo();
|
||||
ruleBo.setProductId(device.getProductId());
|
||||
ruleBo.setSerialNumber(device.getSerialNumber());
|
||||
|
||||
// 查询emqx中设备连接状态
|
||||
String emqxConnected = getEmqxConnected(clientid);
|
||||
// 设备状态(1-未激活,2-禁用,3-在线,4-离线)
|
||||
if ("client.disconnected".equals(event) && "false".equals(emqxConnected)) {
|
||||
device.setStatus(DeviceStatus.OFFLINE.getType());
|
||||
deviceService.updateDeviceStatusAndLocation(device, "");
|
||||
// 设备掉线后发布设备状态
|
||||
messagePublish.publishStatus(device.getProductId(), device.getSerialNumber(), DeviceStatus.OFFLINE.getType(), device.getIsShadow(),device.getRssi());
|
||||
// 清空保留消息,上线后发布新的属性功能保留消息
|
||||
messagePublish.publishProperty(device.getProductId(), device.getSerialNumber(), null,0);
|
||||
messagePublish.publishFunction(device.getProductId(), device.getSerialNumber(), null,0);
|
||||
// 规则匹配处理(告警和场景联动)
|
||||
ruleBo.setType(6);
|
||||
ruleEngine.ruleMatch(ruleBo);
|
||||
} else if ("client.connected".equals(event) && device.getStatus() != DeviceStatus.ONLINE.getType()) {
|
||||
device.setStatus(DeviceStatus.ONLINE.getType());
|
||||
deviceService.updateDeviceStatusAndLocation(device, ipAddress);
|
||||
// 设备掉线后发布设备状态
|
||||
messagePublish.publishStatus(device.getProductId(), device.getSerialNumber(), DeviceStatus.ONLINE.getType(), device.getIsShadow(),device.getRssi());
|
||||
} else if("session.subscribed".equals(event)){
|
||||
// 影子模式,发布属性和功能
|
||||
if (device.getIsShadow() == 1) {
|
||||
ThingsModelShadow shadow = deviceService.getDeviceShadowThingsModel(device);
|
||||
if (shadow.getProperties().size() > 0) {
|
||||
messagePublish.publishProperty(device.getProductId(), device.getSerialNumber(), shadow.getProperties(),3);
|
||||
}
|
||||
if (shadow.getFunctions().size() > 0) {
|
||||
messagePublish.publishFunction(device.getProductId(), device.getSerialNumber(), shadow.getFunctions(),3);
|
||||
}
|
||||
}
|
||||
// 规则匹配处理(告警和场景联动,上线放到设备订阅主题之后,保证设备执行动作能订阅和处理)
|
||||
ruleBo.setType(5);
|
||||
ruleEngine.ruleMatch(ruleBo);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
log.error("发生错误:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取emqx连接状态
|
||||
* @param clientid
|
||||
* @return
|
||||
*/
|
||||
public String getEmqxConnected(String clientid) {
|
||||
String apiKey = emqxApiConfig.getApiKey();
|
||||
String apiSecret = emqxApiConfig.getApiSecret();
|
||||
if ("ApiKey".equals(apiKey) || StringUtils.isEmpty(apiKey) || "ApiSecret".equals(apiSecret) || StringUtils.isEmpty(apiSecret)){
|
||||
return "false";
|
||||
}
|
||||
String url = "http://" + emqxApiConfig.getHost() + ":" + emqxApiConfig.getPort() + "/api/v5/clients/" + clientid;
|
||||
ForestRequest<?> request = Forest.request();
|
||||
request.setUrl(url);
|
||||
request.setType(ForestRequestType.GET);
|
||||
request.addHeader("Content-Type", "application/json");
|
||||
request.addHeader("Authorization", Credentials.basic(emqxApiConfig.getApiKey(), emqxApiConfig.getApiSecret()));
|
||||
ForestResponse response = request.execute(ForestResponse.class);;
|
||||
String execute = response.getResult().toString();
|
||||
if(response.statusCode() == 200) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(execute);
|
||||
return jsonObject.getString("connected");
|
||||
}else if(response.statusCode() == 404) { // 404表示设备断开连接,设备断开连接后,emqx会删除该客户端,所以连接也会删除
|
||||
return "false";
|
||||
}else {
|
||||
throw new RuntimeException("emqx连接状态查询失败:" + execute + ",响应码:" + response.statusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("获取NTP时间")
|
||||
@GetMapping("/ntp")
|
||||
public JSONObject ntp(@RequestParam Long deviceSendTime) {
|
||||
JSONObject ntpJson = new JSONObject();
|
||||
ntpJson.put("deviceSendTime", deviceSendTime);
|
||||
ntpJson.put("serverRecvTime", System.currentTimeMillis());
|
||||
ntpJson.put("serverSendTime", System.currentTimeMillis());
|
||||
return ntpJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("文件上传")
|
||||
public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
||||
try {
|
||||
String filePath = RuoYiConfig.getProfile();
|
||||
// 文件名长度限制
|
||||
int fileNamelength = file.getOriginalFilename().length();
|
||||
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
|
||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||
}
|
||||
// 文件类型限制
|
||||
// assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||
|
||||
// 获取文件名和文件类型
|
||||
String fileName = file.getOriginalFilename();
|
||||
String extension = getExtension(file);
|
||||
//设置日期格式
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MMdd-HHmmss");
|
||||
fileName = "/iot/" + getLoginUser().getUserId().toString() + "/" + df.format(new Date()) + "." + extension;
|
||||
//创建目录
|
||||
File desc = new File(filePath + File.separator + fileName);
|
||||
if (!desc.exists()) {
|
||||
if (!desc.getParentFile().exists()) {
|
||||
desc.getParentFile().mkdirs();
|
||||
}
|
||||
}
|
||||
// 存储文件
|
||||
file.transferTo(desc);
|
||||
|
||||
String url = "/profile" + fileName;
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("fileName", url);
|
||||
ajax.put("url", url);
|
||||
return ajax;
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
@ApiOperation("文件下载")
|
||||
@GetMapping("/download")
|
||||
public void download(String fileName, HttpServletResponse response, HttpServletRequest request) {
|
||||
try {
|
||||
// if (!FileUtils.checkAllowDownload(fileName)) {
|
||||
// throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
||||
// }
|
||||
String filePath = RuoYiConfig.getProfile();
|
||||
// 资源地址
|
||||
String downloadPath = filePath + fileName.replace("/profile", "");
|
||||
// 下载名称
|
||||
String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, downloadName);
|
||||
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成代码
|
||||
*/
|
||||
@Log(title = "SDK生成", businessType = BusinessType.GENCODE)
|
||||
@GetMapping("/genSdk")
|
||||
@ApiOperation("生成SDK")
|
||||
public void genSdk(HttpServletResponse response, int deviceChip) throws IOException {
|
||||
byte[] data = downloadCode(deviceChip);
|
||||
genSdk(response, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成zip文件
|
||||
*/
|
||||
private void genSdk(HttpServletResponse response, byte[] data) throws IOException {
|
||||
response.reset();
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"fastbee.zip\"");
|
||||
response.addHeader("Content-Length", "" + data.length);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IOUtils.write(data, response.getOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成代码(下载方式)
|
||||
*
|
||||
* @param deviceChip
|
||||
* @return 数据
|
||||
*/
|
||||
public byte[] downloadCode(int deviceChip) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
// generatorCode(deviceChip, zip);
|
||||
IOUtils.closeQuietly(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询表信息并生成代码
|
||||
*/
|
||||
private void generatorCode(int deviceChip, ZipOutputStream zip) {
|
||||
VelocityInitializer.initVelocity();
|
||||
|
||||
VelocityContext context = VelocityUtils.prepareContext(deviceChip);
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList("");
|
||||
for (String template : templates) {
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
try {
|
||||
// 添加到zip
|
||||
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template)));
|
||||
IOUtils.write(sw.toString(), zip, Constants.UTF8);
|
||||
IOUtils.closeQuietly(sw);
|
||||
zip.flush();
|
||||
zip.closeEntry();
|
||||
} catch (IOException e) {
|
||||
System.out.println("渲染模板失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/getTopics")
|
||||
@ApiOperation("获取所有下发的topic")
|
||||
public AjaxResult getTopics(Boolean isSimulate){
|
||||
return AjaxResult.success(TopicsUtils.getAllGet(isSimulate));
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
@ApiOperation("指令编码")
|
||||
public AjaxResult decode(DeCodeBo bo){
|
||||
return AjaxResult.success(deCodeService.protocolDeCode(bo));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.fastbee.data.controller;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.iot.service.IUserSocialProfileService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 第三方登录平台控制Controller
|
||||
*
|
||||
* @author json
|
||||
* @date 2022-04-24
|
||||
*/
|
||||
@Api(tags = "用户社交账户api")
|
||||
@RestController
|
||||
@RequestMapping("/iot/social/")
|
||||
public class UserSocialController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IUserSocialProfileService iUserSocialProfileService;
|
||||
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @param bindId 绑定id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/bindId/{bindId}")
|
||||
@ApiOperation("绑定api")
|
||||
@ApiImplicitParam(name = "bindId", value = "绑定bindId", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult bindUser(@PathVariable String bindId) {
|
||||
return iUserSocialProfileService.bindUser(bindId, getUserId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
*
|
||||
* @param platform 绑定类型
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/bind/{platform}")
|
||||
@ApiOperation("绑定跳转api")
|
||||
@ApiImplicitParam(name = "platform", value = "绑定platform", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
|
||||
public AjaxResult bind(@PathVariable String platform) {
|
||||
return iUserSocialProfileService.bindSocialAccount(platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑
|
||||
*
|
||||
* @param socialUserId 用户社交平台Id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/unbind/{socialUserId}")
|
||||
@ApiOperation("解绑api")
|
||||
@ApiImplicitParam(name = "socialUserId", value = "绑定socialId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public AjaxResult unbind(@PathVariable Long socialUserId) {
|
||||
return iUserSocialProfileService.unbindSocialAccount(socialUserId, getUserId());
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.fastbee.data.controller.dashBoard;
|
||||
|
||||
import com.fastbee.common.constant.FastBeeConstant;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.redis.RedisCache;
|
||||
import com.fastbee.iot.model.dashBoard.DashMqttMetrics;
|
||||
import com.fastbee.iot.model.dashBoard.DashMqttStat;
|
||||
import com.fastbee.mqtt.manager.ClientManager;
|
||||
import com.fastbee.mqtt.manager.RetainMsgManager;
|
||||
import com.fastbee.base.service.ISessionStore;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 首页面板和大屏数据
|
||||
*
|
||||
* @author gsb
|
||||
* @date 2023/3/27 17:00
|
||||
*/
|
||||
@Api(tags = "首页面板和大屏数据")
|
||||
@RestController
|
||||
@RequestMapping("/bashBoard")
|
||||
public class DashBoardController {
|
||||
|
||||
@Resource
|
||||
private RedisCache redisCache;
|
||||
@Resource
|
||||
private ISessionStore sessionStore;
|
||||
|
||||
@GetMapping("/stats")
|
||||
@ApiOperation("mqtt状态数据")
|
||||
public AjaxResult stats() {
|
||||
DashMqttStat stat = DashMqttStat.builder()
|
||||
.connection_count(sessionStore.getSessionMap().size())
|
||||
.connection_total(getTotal(FastBeeConstant.REDIS.MESSAGE_CONNECT_TOTAL))
|
||||
.subscription_count(ClientManager.topicMap.size())
|
||||
.subscription_total(getTotal(FastBeeConstant.REDIS.MESSAGE_SUBSCRIBE_TOTAL))
|
||||
.retain_count(RetainMsgManager.getSize())
|
||||
.retain_total(getTotal(FastBeeConstant.REDIS.MESSAGE_RETAIN_TOTAL))
|
||||
.session_count(sessionStore.getSessionMap().size())
|
||||
.session_total(getTotal(FastBeeConstant.REDIS.MESSAGE_CONNECT_TOTAL))
|
||||
.build();
|
||||
return AjaxResult.success(stat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/metrics")
|
||||
@ApiOperation("mqtt统计")
|
||||
public AjaxResult metrics() {
|
||||
DashMqttMetrics metrics = DashMqttMetrics.builder()
|
||||
.send_total(getTotal(FastBeeConstant.REDIS.MESSAGE_SEND_TOTAL))
|
||||
.receive_total(getTotal(FastBeeConstant.REDIS.MESSAGE_RECEIVE_TOTAL))
|
||||
.auth_total(getTotal(FastBeeConstant.REDIS.MESSAGE_AUTH_TOTAL))
|
||||
.connect_total(getTotal(FastBeeConstant.REDIS.MESSAGE_CONNECT_TOTAL))
|
||||
.subscribe_total(getTotal(FastBeeConstant.REDIS.MESSAGE_SUBSCRIBE_TOTAL))
|
||||
.today_received(getTotal(FastBeeConstant.REDIS.MESSAGE_RECEIVE_TODAY))
|
||||
.today_send(getTotal(FastBeeConstant.REDIS.MESSAGE_SEND_TODAY))
|
||||
.build();
|
||||
return AjaxResult.success(metrics);
|
||||
}
|
||||
|
||||
|
||||
public Integer getTotal(String key) {
|
||||
return redisCache.getCacheObject(key) == null ? 0 : redisCache.getCacheObject(key);
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.fastbee.data.controller.datacenter;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.annotation.Anonymous;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.iot.domain.DeviceLog;
|
||||
import com.fastbee.iot.model.AlertCountVO;
|
||||
import com.fastbee.iot.model.DeviceHistoryParam;
|
||||
import com.fastbee.iot.model.HistoryModel;
|
||||
import com.fastbee.iot.model.ThingsModelLogCountVO;
|
||||
import com.fastbee.iot.model.param.DataCenterParam;
|
||||
import com.fastbee.iot.model.scenemodel.SceneHistoryParam;
|
||||
import com.fastbee.iot.service.DataCenterService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fastbee.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* @author fastb
|
||||
* @version 1.0
|
||||
* @description: 数据中心控制器
|
||||
* @date 2024-06-13 14:09
|
||||
*/
|
||||
@Api(tags = "数据中心管理")
|
||||
@RestController
|
||||
@RequestMapping("/data/center")
|
||||
public class DataCenterController {
|
||||
|
||||
@Resource
|
||||
private DataCenterService dataCenterService;
|
||||
|
||||
/**
|
||||
* 查询设备物模型的历史数据
|
||||
* @param deviceHistoryParam 传参
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@ApiOperation("查询设备的历史数据")
|
||||
@PreAuthorize("@ss.hasPermi('dataCenter:history:list')")
|
||||
@PostMapping("/deviceHistory")
|
||||
public AjaxResult deviceHistory(@RequestBody DeviceHistoryParam deviceHistoryParam)
|
||||
{
|
||||
if (StringUtils.isEmpty(deviceHistoryParam.getSerialNumber())) {
|
||||
return AjaxResult.error("请选择设备");
|
||||
}
|
||||
List<JSONObject> jsonObject = dataCenterService.deviceHistory(deviceHistoryParam);
|
||||
return AjaxResult.success(jsonObject);
|
||||
}
|
||||
|
||||
@ApiOperation("查询场景变量历史数据")
|
||||
@PreAuthorize("@ss.hasPermi('dataCenter:history:list')")
|
||||
@GetMapping("/sceneHistory")
|
||||
public AjaxResult sceneHistory(SceneHistoryParam sceneHistoryParam)
|
||||
{
|
||||
List<JSONObject> jsonObject = dataCenterService.sceneHistory(sceneHistoryParam);
|
||||
return AjaxResult.success(jsonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计告警处理信息
|
||||
* @param dataCenterParam 传参
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@ApiOperation("统计告警处理信息")
|
||||
@PreAuthorize("@ss.hasPermi('dataCenter:analysis:list')")
|
||||
@GetMapping("/countAlertProcess")
|
||||
public AjaxResult countAlertProcess(DataCenterParam dataCenterParam)
|
||||
{
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
dataCenterParam.setTenantId(deptUserId);
|
||||
List<AlertCountVO> alertCountVO = dataCenterService.countAlertProcess(dataCenterParam);
|
||||
return AjaxResult.success(alertCountVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计告警级别信息
|
||||
* @param dataCenterParam 传参
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@ApiOperation("统计告警级别信息")
|
||||
@PreAuthorize("@ss.hasPermi('dataCenter:analysis:list')")
|
||||
@GetMapping("/countAlertLevel")
|
||||
public AjaxResult countAlertLevel(DataCenterParam dataCenterParam)
|
||||
{
|
||||
Long deptUserId = getLoginUser().getUser().getDept().getDeptUserId();
|
||||
dataCenterParam.setTenantId(deptUserId);
|
||||
List<AlertCountVO> alertCountVO = dataCenterService.countAlertLevel(dataCenterParam);
|
||||
return AjaxResult.success(alertCountVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计设备物模型指令下发数量
|
||||
* @param dataCenterParam 传参
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
@ApiOperation("统计设备物模型指令下发数量")
|
||||
@PreAuthorize("@ss.hasPermi('dataCenter:analysis:list')")
|
||||
@GetMapping("/countThingsModelInvoke")
|
||||
public AjaxResult countThingsModelInvoke(DataCenterParam dataCenterParam)
|
||||
{
|
||||
if (StringUtils.isEmpty(dataCenterParam.getSerialNumber())) {
|
||||
return AjaxResult.error("请传入设备编号");
|
||||
}
|
||||
List<ThingsModelLogCountVO> list = dataCenterService.countThingsModelInvoke(dataCenterParam);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package com.fastbee.data.controller.firmware;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.Firmware;
|
||||
import com.fastbee.iot.service.IFirmwareService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 产品固件Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
@Api(tags = "产品固件")
|
||||
@RestController
|
||||
@RequestMapping("/iot/firmware")
|
||||
public class FirmwareController extends BaseController
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(FirmwareController.class);
|
||||
|
||||
@Autowired
|
||||
private IFirmwareService firmwareService;
|
||||
|
||||
/**
|
||||
* 查询产品固件列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("产品固件分页列表")
|
||||
public TableDataInfo list(Firmware firmware)
|
||||
{
|
||||
startPage();
|
||||
return getDataTable(firmwareService.selectFirmwareList(firmware));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询待升级固件版本列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:list')")
|
||||
@GetMapping("/upGradeVersionList")
|
||||
@ApiOperation("查询待升级固件版本列表")
|
||||
public AjaxResult upGradeVersionList(Firmware firmware) {
|
||||
return AjaxResult.success(firmwareService.selectUpGradeVersionList(firmware));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出产品固件列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:export')")
|
||||
@Log(title = "产品固件", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出固件")
|
||||
public void export(HttpServletResponse response, Firmware firmware)
|
||||
{
|
||||
List<Firmware> list = firmwareService.selectFirmwareList(firmware);
|
||||
ExcelUtil<Firmware> util = new ExcelUtil<Firmware>(Firmware.class);
|
||||
util.exportExcel(response, list, "产品固件数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品固件详细信息
|
||||
*/
|
||||
@ApiOperation("获取固件详情")
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:query')")
|
||||
@GetMapping(value = "/{firmwareId}")
|
||||
public AjaxResult getInfo(@PathVariable("firmwareId") Long firmwareId)
|
||||
{
|
||||
return AjaxResult.success(firmwareService.selectFirmwareByFirmwareId(firmwareId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备最新固件
|
||||
*/
|
||||
@ApiOperation("获取设备最新固件")
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:query')")
|
||||
@GetMapping(value = "/getLatest/{deviceId}")
|
||||
public AjaxResult getLatest(@PathVariable("deviceId") Long deviceId)
|
||||
{
|
||||
return AjaxResult.success(firmwareService.selectLatestFirmware(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品固件
|
||||
*/
|
||||
@ApiOperation("添加产品固件")
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:add')")
|
||||
@Log(title = "产品固件", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody Firmware firmware)
|
||||
{
|
||||
return toAjax(firmwareService.insertFirmware(firmware));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品固件
|
||||
*/
|
||||
@ApiOperation("修改产品固件")
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:edit')")
|
||||
@Log(title = "产品固件", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody Firmware firmware)
|
||||
{
|
||||
return toAjax(firmwareService.updateFirmware(firmware));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品固件
|
||||
*/
|
||||
@ApiOperation("批量删除产品固件")
|
||||
@PreAuthorize("@ss.hasPermi('iot:firmware:remove')")
|
||||
@Log(title = "产品固件", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{firmwareIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] firmwareIds)
|
||||
{
|
||||
return toAjax(firmwareService.deleteFirmwareByFirmwareIds(firmwareIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
package com.fastbee.data.controller.firmware;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeDelayTask;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.data.config.DelayUpgradeQueue;
|
||||
import com.fastbee.data.service.IOtaUpgradeService;
|
||||
import com.fastbee.iot.domain.FirmwareTaskDetail;
|
||||
import com.fastbee.iot.model.FirmwareTaskDetailInput;
|
||||
import com.fastbee.iot.model.FirmwareTaskDetailOutput;
|
||||
import com.fastbee.iot.model.FirmwareTaskDeviceStatistic;
|
||||
import com.fastbee.iot.model.FirmwareTaskInput;
|
||||
import com.fastbee.iot.service.IFirmwareTaskDetailService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.FirmwareTask;
|
||||
import com.fastbee.iot.service.IFirmwareTaskService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 固件升级任务 Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-10-26
|
||||
*/
|
||||
@Api(tags = "固件升级任务")
|
||||
@RestController
|
||||
@RequestMapping("/iot/firmware/task")
|
||||
public class FirmwareTaskController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IFirmwareTaskService firmwareTaskService;
|
||||
@Autowired
|
||||
private IOtaUpgradeService otaUpgradeService;
|
||||
@Autowired
|
||||
private IFirmwareTaskDetailService firmwareTaskDetailService;
|
||||
|
||||
/**
|
||||
* 查询固件升级任务列表
|
||||
*/
|
||||
@ApiOperation("查询固件升级任务列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(FirmwareTask firmwareTask)
|
||||
{
|
||||
startPage();
|
||||
List<FirmwareTask> list = firmwareTaskService.selectFirmwareTaskList(firmwareTask);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据固件id查询下属设备列表
|
||||
*/
|
||||
@ApiOperation("根据固件id查询下属设备列表")
|
||||
@GetMapping("/deviceList")
|
||||
public TableDataInfo deviceList(FirmwareTaskDetailInput FirmwareTaskDetailInput) {
|
||||
startPage();
|
||||
List<FirmwareTaskDetailOutput> list = firmwareTaskDetailService.selectFirmwareTaskDetailListByFirmwareId(FirmwareTaskDetailInput);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 固件升级设备统计
|
||||
*/
|
||||
@ApiOperation("固件升级设备统计")
|
||||
@GetMapping("/deviceStatistic")
|
||||
public AjaxResult deviceStatistic(FirmwareTaskDetailInput FirmwareTaskDetailInput) {
|
||||
List<FirmwareTaskDeviceStatistic> list = firmwareTaskDetailService.deviceStatistic(FirmwareTaskDetailInput);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出固件升级任务列表
|
||||
*/
|
||||
@ApiOperation("导出固件升级任务列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:export')")
|
||||
@Log(title = "固件升级任务", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, FirmwareTask firmwareTask)
|
||||
{
|
||||
List<FirmwareTask> list = firmwareTaskService.selectFirmwareTaskList(firmwareTask);
|
||||
ExcelUtil<FirmwareTask> util = new ExcelUtil<FirmwareTask>(FirmwareTask.class);
|
||||
util.exportExcel(response, list, "固件升级任务数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取固件升级任务详细信息
|
||||
*/
|
||||
@ApiOperation("获取固件升级任务详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return AjaxResult.success(firmwareTaskService.selectFirmwareTaskById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增固件升级任务
|
||||
*/
|
||||
@ApiOperation("新增固件升级任务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:add')")
|
||||
@Log(title = "固件升级任务", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody FirmwareTaskInput firmwareTaskInput) {
|
||||
Long taskId = firmwareTaskService.insertFirmwareTask(firmwareTaskInput);
|
||||
if (taskId > 0){
|
||||
OtaUpgradeDelayTask otaTask = new OtaUpgradeDelayTask();
|
||||
otaTask.setTaskId(taskId);
|
||||
otaTask.setFirmwareId(firmwareTaskInput.getFirmwareId());
|
||||
otaTask.setDevices(firmwareTaskInput.getDeviceList());
|
||||
otaTask.setStartTime(firmwareTaskInput.getBookTime());
|
||||
return upgrade(otaTask);
|
||||
}else {
|
||||
return AjaxResult.error("创建升级任务失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改固件升级任务
|
||||
*/
|
||||
@ApiOperation("修改固件升级任务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:edit')")
|
||||
@Log(title = "固件升级任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody FirmwareTask firmwareTask)
|
||||
{
|
||||
return toAjax(firmwareTaskService.updateFirmwareTask(firmwareTask));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除固件升级任务
|
||||
*/
|
||||
@ApiOperation("删除固件升级任务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:remove')")
|
||||
@Log(title = "固件升级任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(firmwareTaskService.deleteFirmwareTaskByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 固件升级
|
||||
*/
|
||||
@PostMapping("/upgrade")
|
||||
@PreAuthorize("@ss.hasPermi('iot:task:upgrade')")
|
||||
@ApiOperation(value = "固件升级", httpMethod = "POST", response = AjaxResult.class, notes = "固件升级")
|
||||
public AjaxResult upgrade(@RequestBody OtaUpgradeDelayTask task){
|
||||
// 判定是否是预定升级时间升级
|
||||
if (null != task.getStartTime()){
|
||||
if (DateUtils.getNowDate().after(task.getStartTime())){
|
||||
throw new ServiceException(MessageUtils.message("firmware.task.upgrade.failed.time.not.valid"));
|
||||
}
|
||||
//预定升级的任务放到 延迟任务队列
|
||||
DelayUpgradeQueue.offerTask(task);
|
||||
FirmwareTask updatePo = new FirmwareTask();
|
||||
updatePo.setId(task.getTaskId());
|
||||
updatePo.setBookTime(task.getStartTime());
|
||||
firmwareTaskService.updateFirmwareTask(updatePo);
|
||||
}else {
|
||||
otaUpgradeService.upgrade(task);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/upgrade/detail")
|
||||
@ApiOperation(value = "查询OTA升级详情列表")
|
||||
public TableDataInfo taskDetails(FirmwareTaskDetail detail){
|
||||
startPage();
|
||||
List<FirmwareTaskDetail> detailList = firmwareTaskDetailService.selectFirmwareTaskDetailList(detail);
|
||||
return getDataTable(detailList);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package com.fastbee.data.controller.firmware;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.ViewConfig;
|
||||
import com.fastbee.iot.service.IViewConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 界面可视化配置Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-11-15
|
||||
*/
|
||||
@Api(tags = "界面可视化配置")
|
||||
@RestController
|
||||
@RequestMapping("/iot/viewConfig")
|
||||
public class ViewConfigController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IViewConfigService viewConfigService;
|
||||
|
||||
/**
|
||||
* 查询界面可视化配置列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("界面可视化配置分页列表")
|
||||
public TableDataInfo list(ViewConfig viewConfig)
|
||||
{
|
||||
startPage();
|
||||
List<ViewConfig> list = viewConfigService.selectViewConfigList(viewConfig);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出界面可视化配置列表
|
||||
*/
|
||||
@Log(title = "界面可视化配置", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出界面可视化配置")
|
||||
public void export(HttpServletResponse response, ViewConfig viewConfig)
|
||||
{
|
||||
List<ViewConfig> list = viewConfigService.selectViewConfigList(viewConfig);
|
||||
ExcelUtil<ViewConfig> util = new ExcelUtil<ViewConfig>(ViewConfig.class);
|
||||
util.exportExcel(response, list, "界面可视化配置数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取界面可视化配置详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{viewId}")
|
||||
@ApiOperation("获取界面可视化详情")
|
||||
public AjaxResult getInfo(@PathVariable("viewId") Long viewId)
|
||||
{
|
||||
return AjaxResult.success(viewConfigService.selectViewConfigByViewId(viewId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增界面可视化配置
|
||||
*/
|
||||
@Log(title = "界面可视化配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增界面可视化配置")
|
||||
public AjaxResult add(@RequestBody ViewConfig viewConfig)
|
||||
{
|
||||
Long viewId=viewConfigService.insertViewConfig(viewConfig);
|
||||
return AjaxResult.success(viewId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改界面可视化配置
|
||||
*/
|
||||
@Log(title = "界面可视化配置", businessType = BusinessType.UPDATE)
|
||||
@ApiOperation("编辑界面可视化配置")
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ViewConfig viewConfig)
|
||||
{
|
||||
return toAjax(viewConfigService.updateViewConfig(viewConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除界面可视化配置
|
||||
*/
|
||||
@Log(title = "界面可视化配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{viewIds}")
|
||||
@ApiOperation("批量删除界面可视化配置")
|
||||
public AjaxResult remove(@PathVariable Long[] viewIds)
|
||||
{
|
||||
return toAjax(viewConfigService.deleteViewConfigByViewIds(viewIds));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,129 @@
|
||||
package com.fastbee.data.controller.gateway;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.SubGateway;
|
||||
import com.fastbee.iot.model.gateWay.GateSubDeviceVO;
|
||||
import com.fastbee.iot.model.gateWay.SubDeviceAddVO;
|
||||
import com.fastbee.iot.model.gateWay.SubDeviceListVO;
|
||||
import com.fastbee.iot.service.ISubGatewayService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 网关与子设备关联Controller
|
||||
*
|
||||
* @author gsb
|
||||
* @date 2024-05-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sub/gateway")
|
||||
@Api(tags = "网关与子设备关联")
|
||||
public class SubGatewayController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISubGatewayService gatewayService;
|
||||
|
||||
/**
|
||||
* 查询网关与子设备关联列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询网关与子设备关联列表")
|
||||
public TableDataInfo list(SubGateway gateway)
|
||||
{
|
||||
startPage();
|
||||
List<SubDeviceListVO> list = gatewayService.selectGatewayList(gateway);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网关与子设备关联详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取网关与子设备关联详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(gatewayService.selectGatewayById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增网关与子设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:add')")
|
||||
@PostMapping
|
||||
@ApiOperation("新增网关与子设备关联")
|
||||
public AjaxResult add(@RequestBody SubGateway gateway)
|
||||
{
|
||||
return toAjax(gatewayService.insertGateway(gateway));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改网关与子设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:edit')")
|
||||
@PutMapping
|
||||
@ApiOperation("修改网关与子设备关联")
|
||||
public AjaxResult edit(@RequestBody SubGateway gateway)
|
||||
{
|
||||
return toAjax(gatewayService.updateGateway(gateway));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除网关与子设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除网关与子设备关联")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(gatewayService.deleteGatewayByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可选择的网关子设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:query')")
|
||||
@GetMapping(value = "/subDevice")
|
||||
@ApiOperation("获取可选择的网关子设备列表")
|
||||
public TableDataInfo subDevice(GateSubDeviceVO subDeviceVO)
|
||||
{
|
||||
startPage();
|
||||
List<GateSubDeviceVO> subDeviceVOList = gatewayService.getIsSelectGateSubDevice(subDeviceVO);
|
||||
return getDataTable(subDeviceVOList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增网关与子设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:add')")
|
||||
@PostMapping("/addBatch")
|
||||
@ApiOperation("批量新增网关与子设备关联")
|
||||
public AjaxResult addBatch(@RequestBody SubDeviceAddVO subDeviceAddVO)
|
||||
{
|
||||
return toAjax(gatewayService.insertSubDeviceBatch(subDeviceAddVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改网关与子设备关联
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sub:gateway:edit')")
|
||||
@PostMapping("/editBatch")
|
||||
@ApiOperation("批量修改网关与子设备关联")
|
||||
public AjaxResult editBatch(@RequestBody List<SubGateway> list)
|
||||
{
|
||||
gatewayService.updateSubDeviceBatch(list);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.sip.domain.MediaServer;
|
||||
import com.fastbee.sip.service.IMediaServerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流媒体服务器配置Controller
|
||||
*
|
||||
* @author zhuangpeng.li
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Api(tags = "流媒体服务器配置")
|
||||
@RestController
|
||||
@RequestMapping("/sip/mediaserver")
|
||||
public class MediaServerController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
/**
|
||||
* 查询流媒体服务器配置列表
|
||||
*/
|
||||
@ApiOperation("查询流媒体服务器配置列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(MediaServer mediaServer)
|
||||
{
|
||||
startPage();
|
||||
List<MediaServer> list = mediaServerService.selectMediaServerList(mediaServer);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出流媒体服务器配置列表
|
||||
*/
|
||||
@ApiOperation("导出流媒体服务器配置列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@Log(title = "流媒体服务器配置", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, MediaServer mediaServer)
|
||||
{
|
||||
List<MediaServer> list = mediaServerService.selectMediaServerList(mediaServer);
|
||||
ExcelUtil<MediaServer> util = new ExcelUtil<MediaServer>(MediaServer.class);
|
||||
util.exportExcel(response, list, "流媒体服务器配置数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流媒体服务器配置详细信息,只获取第一条
|
||||
*/
|
||||
@ApiOperation(value = "获取流媒体服务器配置详细信息", notes = "只获取第一条")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:query')")
|
||||
@GetMapping()
|
||||
public AjaxResult getInfo()
|
||||
{
|
||||
List<MediaServer> list=mediaServerService.selectMediaServer();
|
||||
if(list==null || list.size()==0){
|
||||
MediaServer mediaServer=new MediaServer();
|
||||
// 设置默认值
|
||||
mediaServer.setEnabled(1);
|
||||
mediaServer.setDomain("");
|
||||
mediaServer.setIp("");
|
||||
mediaServer.setPortHttp(8082L);
|
||||
mediaServer.setPortHttps(8443L);
|
||||
mediaServer.setPortRtmp(1935L);
|
||||
mediaServer.setPortRtsp(554L);
|
||||
mediaServer.setProtocol("HTTP");
|
||||
mediaServer.setSecret("035c73f7-bb6b-4889-a715-d9eb2d192xxx");
|
||||
mediaServer.setRtpPortRange("30000,30500");
|
||||
list=new ArrayList<>();
|
||||
list.add(mediaServer);
|
||||
}
|
||||
return AjaxResult.success(list.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增流媒体服务器配置
|
||||
*/
|
||||
@ApiOperation("新增流媒体服务器配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:add')")
|
||||
@Log(title = "流媒体服务器配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody MediaServer mediaServer)
|
||||
{
|
||||
return toAjax(mediaServerService.insertMediaServer(mediaServer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改流媒体服务器配置
|
||||
*/
|
||||
@ApiOperation("修改流媒体服务器配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:edit')")
|
||||
@Log(title = "流媒体服务器配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody MediaServer mediaServer)
|
||||
{
|
||||
return toAjax(mediaServerService.updateMediaServer(mediaServer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流媒体服务器配置
|
||||
*/
|
||||
@ApiOperation("删除流媒体服务器配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:remove')")
|
||||
@Log(title = "流媒体服务器配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(mediaServerService.deleteMediaServerByIds(ids));
|
||||
}
|
||||
|
||||
@ApiOperation("获取流媒体服务器视频流信息列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/mediaList/{schema}/{stream}")
|
||||
public AjaxResult getMediaList(@PathVariable String schema,
|
||||
@PathVariable String stream)
|
||||
{
|
||||
return AjaxResult.success(MessageUtils.message("success"), mediaServerService.getMediaList(schema,stream));
|
||||
}
|
||||
|
||||
@ApiOperation("获取rtp推流端口列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/listRtpServer")
|
||||
public AjaxResult listRtpServer()
|
||||
{
|
||||
return AjaxResult.success(MessageUtils.message("success"), mediaServerService.listRtpServer());
|
||||
}
|
||||
|
||||
@ApiOperation("检验流媒体服务")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping(value = "/check")
|
||||
public AjaxResult checkMediaServer(@RequestParam String ip, @RequestParam Long port, @RequestParam String secret) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), mediaServerService.checkMediaServer(ip, port, secret));
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.sip.service.IPlayService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sip/player")
|
||||
public class PlayerController extends BaseController {
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@GetMapping("/getBigScreenUrl/{deviceId}/{channelId}")
|
||||
public AjaxResult getBigScreenUrl(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.play(deviceId, channelId,false).getHttps_fmp4());
|
||||
}
|
||||
|
||||
@ApiOperation("直播播放")
|
||||
@GetMapping("/play/{deviceId}/{channelId}")
|
||||
public AjaxResult play(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.play(deviceId, channelId,false));
|
||||
}
|
||||
@ApiOperation("回放播放")
|
||||
@GetMapping("/playback/{deviceId}/{channelId}")
|
||||
public AjaxResult playback(@PathVariable String deviceId,
|
||||
@PathVariable String channelId, String start, String end) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.playback(deviceId, channelId, start, end));
|
||||
}
|
||||
@ApiOperation("停止推流")
|
||||
@GetMapping("/closeStream/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult closeStream(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
|
||||
return AjaxResult.success("success!", playService.closeStream(deviceId, channelId, streamId));
|
||||
}
|
||||
|
||||
@ApiOperation("回放暂停")
|
||||
@GetMapping("/playbackPause/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackPause(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.playbackPause(deviceId, channelId, streamId));
|
||||
}
|
||||
@ApiOperation("回放恢复")
|
||||
@GetMapping("/playbackReplay/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackReplay(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.playbackReplay(deviceId, channelId, streamId));
|
||||
}
|
||||
@ApiOperation("录像回放定位")
|
||||
@GetMapping("/playbackSeek/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackSeek(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId, long seek) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.playbackSeek(deviceId, channelId, streamId, seek));
|
||||
}
|
||||
@ApiOperation("录像倍速播放")
|
||||
@GetMapping("/playbackSpeed/{deviceId}/{channelId}/{streamId}")
|
||||
public AjaxResult playbackSpeed(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String streamId, Integer speed) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), playService.playbackSpeed(deviceId, channelId, streamId, speed));
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.sip.enums.Direct;
|
||||
import com.fastbee.sip.model.PtzDirectionInput;
|
||||
import com.fastbee.sip.model.PtzscaleInput;
|
||||
import com.fastbee.sip.service.IPtzCmdService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sip/ptz")
|
||||
public class PtzController {
|
||||
@Autowired
|
||||
private IPtzCmdService ptzCmdService;
|
||||
@ApiOperation("云台方向控制")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@PostMapping("/direction/{deviceId}/{channelId}")
|
||||
public AjaxResult direction(@PathVariable String deviceId, @PathVariable String channelId, @RequestBody PtzDirectionInput ptzDirectionInput) {
|
||||
Direct direct = null;
|
||||
int leftRight = ptzDirectionInput.getLeftRight();
|
||||
int upDown = ptzDirectionInput.getUpDown();
|
||||
if (leftRight == 1) {
|
||||
direct = Direct.RIGHT;
|
||||
} else if (leftRight == 2) {
|
||||
direct = Direct.LEFT;
|
||||
} else if (upDown == 1) {
|
||||
direct = Direct.UP;
|
||||
} else if (upDown == 2) {
|
||||
direct = Direct.DOWN;
|
||||
} else {
|
||||
direct = Direct.STOP;
|
||||
}
|
||||
Integer speed = ptzDirectionInput.getMoveSpeed();
|
||||
return AjaxResult.success(MessageUtils.message("success"), ptzCmdService.directPtzCmd(deviceId, channelId, direct, speed));
|
||||
}
|
||||
@ApiOperation("云台缩放控制")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@PostMapping("/scale/{deviceId}/{channelId}")
|
||||
public AjaxResult scale(@PathVariable String deviceId, @PathVariable String channelId, @RequestBody PtzscaleInput ptzscaleInput) {
|
||||
Direct direct = null;
|
||||
if (ptzscaleInput.getInOut() == 1) {
|
||||
direct = Direct.ZOOM_IN;
|
||||
} else if (ptzscaleInput.getInOut() == 2) {
|
||||
direct = Direct.ZOOM_OUT;
|
||||
} else {
|
||||
direct = Direct.STOP;
|
||||
}
|
||||
Integer speed = ptzscaleInput.getScaleSpeed();
|
||||
return AjaxResult.success(MessageUtils.message("success"), ptzCmdService.directPtzCmd(deviceId, channelId, direct, speed));
|
||||
}
|
||||
@ApiOperation("云台ptz控制")
|
||||
@PostMapping("/ptz/{deviceId}/{channelId}/{direct}/{speed}")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
public AjaxResult ptzControl(@PathVariable String deviceId,
|
||||
@PathVariable String channelId,
|
||||
@PathVariable Direct direct,
|
||||
@PathVariable Integer speed) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), ptzCmdService.directPtzCmd(deviceId, channelId, direct, speed));
|
||||
}
|
||||
@ApiOperation("云台停止控制")
|
||||
@PostMapping("/ptz/{deviceId}/{channelId}/STOP")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
public AjaxResult ptzControlStop(@PathVariable String deviceId,
|
||||
@PathVariable String channelId) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), ptzCmdService.directPtzCmd(deviceId, channelId, Direct.STOP, 0));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.sip.model.RecordList;
|
||||
import com.fastbee.sip.service.IRecordService;
|
||||
import com.fastbee.sip.util.WebAsyncUtil;
|
||||
import com.fastbee.sip.util.result.BaseResult;
|
||||
import com.fastbee.sip.util.result.CodeEnum;
|
||||
import com.fastbee.sip.util.result.DataResult;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.WebAsyncTask;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sip/record")
|
||||
public class RecordController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IRecordService recordService;
|
||||
|
||||
@Qualifier("taskExecutor")
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor taskExecutor;
|
||||
@ApiOperation("设备录像查询")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/devquery/{deviceId}/{channelId}")
|
||||
public WebAsyncTask<Object> devquery(@PathVariable String deviceId,
|
||||
@PathVariable String channelId, String start, String end) {
|
||||
return WebAsyncUtil.init(taskExecutor, () -> {
|
||||
try {
|
||||
RecordList result = recordService.listDevRecord(deviceId, channelId, start, end);
|
||||
return DataResult.out(CodeEnum.SUCCESS, result);
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
return BaseResult.out(CodeEnum.FAIL, e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ApiOperation("设备录像缓存查询")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/query/{channelId}/{sn}")
|
||||
public AjaxResult list(@PathVariable String channelId,
|
||||
@PathVariable String sn) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), recordService.listRecord(channelId, sn));
|
||||
}
|
||||
|
||||
@ApiOperation("指定流ID开始录像")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/start/{stream}")
|
||||
public AjaxResult startRecord(@PathVariable String stream) {
|
||||
boolean result = recordService.startRecord(stream);
|
||||
if (result) {
|
||||
return AjaxResult.success(MessageUtils.message("success"));
|
||||
} else {
|
||||
return AjaxResult.error("error!");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("指定流ID停止录像")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/stop/{stream}")
|
||||
public AjaxResult stopRecord(@PathVariable String stream) {
|
||||
boolean result = recordService.stopRecord(stream);
|
||||
if (result) {
|
||||
return AjaxResult.success(MessageUtils.message("success"));
|
||||
} else {
|
||||
return AjaxResult.error("error!");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("获取流对应的录像文件列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/file/{stream}/{period}")
|
||||
public AjaxResult getMp4RecordFile(@PathVariable String stream,
|
||||
@PathVariable String period) {
|
||||
return AjaxResult.success(MessageUtils.message("success"), recordService.getMp4RecordFile(stream, period));
|
||||
}
|
||||
|
||||
@ApiOperation("直播录像")
|
||||
@GetMapping("/play/{deviceId}/{channelId}")
|
||||
public AjaxResult playRecord(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
logger.debug(String.format("直播录像 API调用,deviceId:%s,channelId:%s", deviceId, channelId));
|
||||
return AjaxResult.success(MessageUtils.message("success"), recordService.playRecord(deviceId, channelId));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:download')")
|
||||
@ApiOperation("设备录像下载")
|
||||
@GetMapping("/download/{deviceId}/{channelId}")
|
||||
public AjaxResult download(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime, String speed) {
|
||||
logger.debug(String.format("设备录像下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, speed));
|
||||
return AjaxResult.success("success!", recordService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(speed)));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:upload')")
|
||||
@ApiOperation("录像上传OSS")
|
||||
@GetMapping("/upload")
|
||||
public AjaxResult upload(@RequestParam String recordApi, @RequestParam String file) {
|
||||
logger.debug(String.format("录像上传OSS API调用,recordApi:%s,file:%s", recordApi, file));
|
||||
return AjaxResult.success("success!", recordService.upload(recordApi, file));
|
||||
}
|
||||
|
||||
@ApiOperation("查询服务端录像列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:list')")
|
||||
@GetMapping("/serverRecord/list")
|
||||
public AjaxResult listServerRecord(@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize, @RequestParam String recordApi) {
|
||||
try{
|
||||
Object data = recordService.listServerRecord(recordApi, pageNum, pageSize);
|
||||
return AjaxResult.success(MessageUtils.message("success"), data);
|
||||
}catch(Exception e){
|
||||
return AjaxResult.error(MessageUtils.message("media.record.query.failed"));
|
||||
}
|
||||
}
|
||||
@ApiOperation("通过日期查询服务端录像列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:list')")
|
||||
@GetMapping("/serverRecord/date/list")
|
||||
public AjaxResult listServerRecordByDate(@RequestParam(required = false) Integer year,
|
||||
@RequestParam(required = false) Integer month, @RequestParam String app, @RequestParam String stream, @RequestParam String recordApi) {
|
||||
return AjaxResult.success(MessageUtils.message(MessageUtils.message("success")), recordService.listServerRecordByDate(recordApi, year, month, app, stream));
|
||||
}
|
||||
@ApiOperation("通过流ID查询服务端录像列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:list')")
|
||||
@GetMapping("/serverRecord/stream/list")
|
||||
public AjaxResult listServerRecordByStream(@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize, @RequestParam String app, @RequestParam String recordApi) {
|
||||
return AjaxResult.success(MessageUtils.message(MessageUtils.message("success")), recordService.listServerRecordByStream(recordApi, pageNum, pageSize, app));
|
||||
}
|
||||
@ApiOperation("通过应用名查询服务端录像列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:list')")
|
||||
@GetMapping("/serverRecord/app/list")
|
||||
public AjaxResult listServerRecordByApp(@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize, @RequestParam String recordApi) {
|
||||
return AjaxResult.success(MessageUtils.message(MessageUtils.message("success")), recordService.listServerRecordByApp(recordApi, pageNum, pageSize));
|
||||
}
|
||||
@ApiOperation("通过文件名查询服务端录像列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:list')")
|
||||
@GetMapping("/serverRecord/file/list")
|
||||
public AjaxResult listServerRecordByFile(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
|
||||
@RequestParam String app, @RequestParam String stream,
|
||||
@RequestParam String startTime, @RequestParam String endTime, @RequestParam String recordApi) {
|
||||
return AjaxResult.success("success!", recordService.listServerRecordByFile(recordApi, pageNum, pageSize, app, stream, startTime, endTime));
|
||||
}
|
||||
|
||||
@ApiOperation("通过设备信息查询服务端录像列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:sip:record:list')")
|
||||
@GetMapping("/serverRecord/device/list")
|
||||
public AjaxResult getServerRecordByDevice(@RequestParam Integer pageNum, @RequestParam Integer pageSize,
|
||||
@RequestParam String deviceId, @RequestParam String channelId,
|
||||
@RequestParam String startTime, @RequestParam String endTime) {
|
||||
return AjaxResult.success("success!", recordService.listServerRecordByDevice(pageNum, pageSize, deviceId, channelId, startTime, endTime));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.sip.domain.SipConfig;
|
||||
import com.fastbee.sip.service.ISipConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* sip系统配置Controller
|
||||
*
|
||||
* @author zhuangpeng.li
|
||||
* @date 2022-11-30
|
||||
*/
|
||||
@Api(tags = "sip系统配置")
|
||||
@RestController
|
||||
@RequestMapping("/sip/sipconfig")
|
||||
public class SipConfigController extends BaseController {
|
||||
@Autowired
|
||||
private ISipConfigService sipConfigService;
|
||||
|
||||
/**
|
||||
* 获取产品下第一条sip系统配置详细信息
|
||||
*/
|
||||
@ApiOperation("获取产品下sip系统配置信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:query')")
|
||||
@GetMapping(value = "/{productId}")
|
||||
public AjaxResult getInfo(@PathVariable("productId") Long productId) {
|
||||
return AjaxResult.success(sipConfigService.selectSipConfigByProductId(productId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增sip系统配置
|
||||
*/
|
||||
@ApiOperation("新增sip系统配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:add')")
|
||||
@Log(title = "sip系统配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SipConfig sipConfig) {
|
||||
return AjaxResult.success(sipConfigService.insertSipConfig(sipConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改sip系统配置
|
||||
*/
|
||||
@ApiOperation("修改sip系统配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:edit')")
|
||||
@Log(title = "sip系统配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SipConfig sipConfig) {
|
||||
return toAjax(sipConfigService.updateSipConfig(sipConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除sip系统配置
|
||||
*/
|
||||
@ApiOperation("删除sip系统配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:remove')")
|
||||
@Log(title = "sip系统配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(sipConfigService.deleteSipConfigByIds(ids));
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除sip系统配置")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:remove')")
|
||||
@Log(title = "sip系统配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/product/{productIds}")
|
||||
public AjaxResult removeByProductId(@PathVariable Long[] productIds) {
|
||||
// 设备可能不存在通道,可以返回0
|
||||
int result = sipConfigService.deleteSipConfigByProductIds(productIds);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.sip.domain.SipDeviceChannel;
|
||||
import com.fastbee.sip.service.ISipDeviceChannelService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 监控设备通道信息Controller
|
||||
*
|
||||
* @author zhuangpeng.li
|
||||
* @date 2022-10-07
|
||||
*/
|
||||
@Api(tags = "监控设备通道信息")
|
||||
@RestController
|
||||
@RequestMapping("/sip/channel")
|
||||
public class SipDeviceChannelController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISipDeviceChannelService sipDeviceChannelService;
|
||||
|
||||
/**
|
||||
* 查询监控设备通道信息列表
|
||||
*/
|
||||
@ApiOperation("查询监控设备通道信息列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SipDeviceChannel sipDeviceChannel)
|
||||
{
|
||||
startPage();
|
||||
List<SipDeviceChannel> list = sipDeviceChannelService.selectSipDeviceChannelList(sipDeviceChannel);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出监控设备通道信息列表
|
||||
*/
|
||||
@ApiOperation("导出监控设备通道信息列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@Log(title = "监控设备通道信息", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SipDeviceChannel sipDeviceChannel)
|
||||
{
|
||||
List<SipDeviceChannel> list = sipDeviceChannelService.selectSipDeviceChannelList(sipDeviceChannel);
|
||||
ExcelUtil<SipDeviceChannel> util = new ExcelUtil<SipDeviceChannel>(SipDeviceChannel.class);
|
||||
util.exportExcel(response, list, "监控设备通道信息数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控设备通道信息详细信息
|
||||
*/
|
||||
@ApiOperation("获取监控设备通道信息详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:query')")
|
||||
@GetMapping(value = "/{channelId}")
|
||||
public AjaxResult getInfo(@PathVariable("channelId") Long channelId)
|
||||
{
|
||||
return AjaxResult.success(sipDeviceChannelService.selectSipDeviceChannelByChannelId(channelId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增监控设备通道信息
|
||||
*/
|
||||
@ApiOperation("新增监控设备通道信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:add')")
|
||||
@Log(title = "监控设备通道信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/{createNum}")
|
||||
public AjaxResult add(@PathVariable("createNum") Long createNum, @RequestBody SipDeviceChannel sipDeviceChannel) {
|
||||
return AjaxResult.success(MessageUtils.message("operate.success"), sipDeviceChannelService.insertSipDeviceChannelGen(createNum, sipDeviceChannel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改监控设备通道信息
|
||||
*/
|
||||
@ApiOperation("修改监控设备通道信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:edit')")
|
||||
@Log(title = "监控设备通道信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SipDeviceChannel sipDeviceChannel)
|
||||
{
|
||||
return toAjax(sipDeviceChannelService.updateSipDeviceChannel(sipDeviceChannel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监控设备通道信息
|
||||
*/
|
||||
@ApiOperation("删除监控设备通道信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:remove')")
|
||||
@Log(title = "监控设备通道信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{channelIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] channelIds)
|
||||
{
|
||||
return toAjax(sipDeviceChannelService.deleteSipDeviceChannelByChannelIds(channelIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询监控设备通道信息列表
|
||||
*/
|
||||
@ApiOperation("查询监控设备通道信息列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/listRelDeviceOrScene")
|
||||
public AjaxResult listRelDeviceOrScene(String serialNumber, Long sceneModelId)
|
||||
{
|
||||
List<SipDeviceChannel> list = sipDeviceChannelService.listRelDeviceOrScene(serialNumber, sceneModelId);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fastbee.common.utils.file.FileUploadUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.service.ISipDeviceService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 监控设备Controller
|
||||
*
|
||||
* @author zhuangpeng.li
|
||||
* @date 2022-10-07
|
||||
*/
|
||||
@Api(tags = "监控设备")
|
||||
@RestController
|
||||
@RequestMapping("/sip/device")
|
||||
public class SipDeviceController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISipDeviceService sipDeviceService;
|
||||
|
||||
/**
|
||||
* 查询监控设备列表
|
||||
*/
|
||||
@ApiOperation("查询监控设备列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SipDevice sipDevice)
|
||||
{
|
||||
startPage();
|
||||
List<SipDevice> list = sipDeviceService.selectSipDeviceList(sipDevice);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@ApiOperation("查询监控设备树结构")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@GetMapping("/listchannel/{deviceId}")
|
||||
public AjaxResult listchannel(@PathVariable("deviceId") String deviceId)
|
||||
{
|
||||
return AjaxResult.success(sipDeviceService.selectSipDeviceChannelList(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出监控设备列表
|
||||
*/
|
||||
@ApiOperation("导出监控设备列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:list')")
|
||||
@Log(title = "监控设备", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SipDevice sipDevice)
|
||||
{
|
||||
List<SipDevice> list = sipDeviceService.selectSipDeviceList(sipDevice);
|
||||
ExcelUtil<SipDevice> util = new ExcelUtil<SipDevice>(SipDevice.class);
|
||||
util.exportExcel(response, list, "监控设备数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监控设备详细信息
|
||||
*/
|
||||
@ApiOperation("获取监控设备详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:query')")
|
||||
@GetMapping(value = "/{deviceId}")
|
||||
public AjaxResult getInfo(@PathVariable("deviceId") String deviceId)
|
||||
{
|
||||
return AjaxResult.success(sipDeviceService.selectSipDeviceBySipId(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增监控设备
|
||||
*/
|
||||
@ApiOperation("新增监控设备")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:add')")
|
||||
@Log(title = "监控设备", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SipDevice sipDevice)
|
||||
{
|
||||
return toAjax(sipDeviceService.insertSipDevice(sipDevice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改监控设备
|
||||
*/
|
||||
@ApiOperation("修改监控设备")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:edit')")
|
||||
@Log(title = "监控设备", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SipDevice sipDevice)
|
||||
{
|
||||
return toAjax(sipDeviceService.updateSipDevice(sipDevice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监控设备
|
||||
*/
|
||||
@ApiOperation("根据设备id批量删除监控设备")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:remove')")
|
||||
@Log(title = "监控设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{deviceIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] deviceIds)
|
||||
{
|
||||
return toAjax(sipDeviceService.deleteSipDeviceByDeviceIds(deviceIds));
|
||||
}
|
||||
|
||||
@ApiOperation("根据sipId删除")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:remove')")
|
||||
@Log(title = "监控设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/sipid/{sipId}")
|
||||
public AjaxResult remove(@PathVariable String sipId)
|
||||
{
|
||||
return toAjax(sipDeviceService.deleteSipDeviceBySipId(sipId));
|
||||
}
|
||||
|
||||
@ApiOperation("根据设备id捕捉")
|
||||
@PreAuthorize("@ss.hasPermi('iot:video:query')")
|
||||
@GetMapping("/snap/{deviceId}/{channelId}")
|
||||
public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId) {
|
||||
try {
|
||||
final InputStream in = Files.newInputStream(new File(FileUploadUtils.getDefaultBaseDir() + File.separator + "snap" + File.separator + deviceId + "_" + channelId + ".jpg").toPath());
|
||||
resp.setContentType(MediaType.IMAGE_PNG_VALUE);
|
||||
IOUtils.copy(in, resp.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fastbee.sip.service.IZmlHookService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/zlmhook")
|
||||
public class ZmlHookController
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private IZmlHookService zmlHookService;
|
||||
@ApiOperation("访问流媒体服务器上的文件时触发回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_http_access", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onHttpAccess(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onHttpAccess(json).toString(), HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("播放器鉴权事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onPlay(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onPlay(json).toString(), HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("rtsp/rtmp/rtp推流鉴权事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onPublish(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onPublish(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("流无人观看时事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_stream_none_reader", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onStreamNoneReader(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onStreamNoneReader(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("流未找到事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onStreamNotFound(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onStreamNotFound(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("流注册或注销时触发此事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_stream_changed", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onStreamChanged(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onStreamChanged(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("流量统计事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_flow_report", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onFlowReport(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onFlowReport(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation("rtp服务器长时间未收到数据超时回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_rtp_server_timeout", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onRtpServerTimeout(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onRtpServerTimeout(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("rtp发送停止回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_send_rtp_stopped", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onSendRtpStopped(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onSendRtpStopped(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("录制mp4完成后通知事件回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onRecordMp4(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onRecordMp4(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("流媒体服务器启动回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_server_started", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onServerStarted(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onServerStarted(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("流媒体服务器心跳回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onServerKeepalive(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onServerKeepalive(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("流媒体服务器存活回调")
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_server_exited", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onServerExited(@RequestBody JSONObject json){
|
||||
return new ResponseEntity<String>(zmlHookService.onServerExited(json).toString(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
package com.fastbee.data.controller.modbus;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.ModbusConfig;
|
||||
import com.fastbee.iot.domain.ThingsModel;
|
||||
import com.fastbee.iot.model.modbus.ModbusConfigVO;
|
||||
import com.fastbee.iot.model.modbus.ModbusDataImport;
|
||||
import com.fastbee.iot.model.modbus.ModbusIoImport;
|
||||
import com.fastbee.iot.service.IModbusConfigService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.aspectj.weaver.ast.Var;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* modbus配置Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/modbus/config")
|
||||
@Api(tags = "modbus配置")
|
||||
public class ModbusConfigController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IModbusConfigService modbusConfigService;
|
||||
|
||||
/**
|
||||
* 查询modbus配置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ModbusConfig modbusConfig)
|
||||
{
|
||||
startPage();
|
||||
List<ModbusConfig> list = modbusConfigService.selectModbusConfigList(modbusConfig);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取modbus配置详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(modbusConfigService.selectModbusConfigById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增modbus配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:add')")
|
||||
@Log(title = "modbus配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ModbusConfig modbusConfig)
|
||||
{
|
||||
return toAjax(modbusConfigService.insertModbusConfig(modbusConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改modbus配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:edit')")
|
||||
@Log(title = "modbus配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ModbusConfig modbusConfig)
|
||||
{
|
||||
return toAjax(modbusConfigService.updateModbusConfig(modbusConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增或修改modbus配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:add')")
|
||||
@PostMapping("/addBatch")
|
||||
@ApiOperation("批量新增或修改modbus配置")
|
||||
public AjaxResult addBatch(@RequestBody ModbusConfigVO modbusConfigVO)
|
||||
{
|
||||
modbusConfigService.addOrUpModbusConfigBatch(modbusConfigVO.getConfigList(),
|
||||
modbusConfigVO.getProductId(), modbusConfigVO.getDelIds());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除modbus配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:remove')")
|
||||
@Log(title = "modbus配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(modbusConfigService.deleteModbusConfigByIds(ids));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导入MODBUS配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:import')")
|
||||
@ApiOperation(value = "导入MODBUS配置")
|
||||
@PostMapping(value = "/importModbus")
|
||||
public AjaxResult importModbus(MultipartFile file, Integer type,Long productId) throws Exception{
|
||||
assert !Objects.isNull(type) : MessageUtils.message("modbus.type.null");
|
||||
if (type == 1){
|
||||
ExcelUtil<ModbusIoImport> excelUtil = new ExcelUtil<>(ModbusIoImport.class);
|
||||
List<ModbusIoImport> list = excelUtil.importExcel(file.getInputStream());
|
||||
return modbusConfigService.importIOModbus(list, productId, type);
|
||||
}else {
|
||||
ExcelUtil<ModbusDataImport> excelUtil = new ExcelUtil<>(ModbusDataImport.class);
|
||||
List<ModbusDataImport> list = excelUtil.importExcel(file.getInputStream());
|
||||
return modbusConfigService.importDataModbus(list, productId, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出modbus配置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:config:export')")
|
||||
@PostMapping(value = "/exportModbus")
|
||||
@ApiOperation(value = "导出MODBUS配置")
|
||||
public void export(HttpServletResponse response, ModbusConfig modbusConfig)
|
||||
{
|
||||
Integer type = modbusConfig.getType();
|
||||
assert !Objects.isNull(type) : MessageUtils.message("modbus.type.null");
|
||||
if (type == 1){
|
||||
List<ModbusIoImport> list = modbusConfigService.exportTransIO(modbusConfig);
|
||||
ExcelUtil<ModbusIoImport> util = new ExcelUtil<ModbusIoImport>(ModbusIoImport.class);
|
||||
util.exportExcel(response, list, "modbus配置数据");
|
||||
}else {
|
||||
List<ModbusDataImport> list = modbusConfigService.exportTransData(modbusConfig);
|
||||
ExcelUtil<ModbusDataImport> util = new ExcelUtil<ModbusDataImport>(ModbusDataImport.class);
|
||||
util.exportExcel(response, list, "modbus配置数据");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "导入模板")
|
||||
@PostMapping("/modbusTemplate")
|
||||
public void modbusTemplate(HttpServletResponse response, @RequestParam(name= "type") Integer type){
|
||||
if (1 == type){
|
||||
ExcelUtil<ModbusIoImport> excelUtil = new ExcelUtil<>(ModbusIoImport.class);
|
||||
excelUtil.importTemplateExcel(response,"MODBUS-IO");
|
||||
}else {
|
||||
ExcelUtil<ModbusDataImport> excelUtil = new ExcelUtil<>(ModbusDataImport.class);
|
||||
excelUtil.importTemplateExcel(response,"MODBUS-DATA");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.fastbee.data.controller.modbus;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.ModbusJob;
|
||||
import com.fastbee.iot.service.IModbusJobService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 轮训任务列Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-07-05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/modbus/job")
|
||||
@Api(tags = "modbus轮询任务")
|
||||
public class ModbusJobController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private IModbusJobService modbusJobService;
|
||||
|
||||
/**
|
||||
* 查询轮训任务列列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:job:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询轮训任务列列表")
|
||||
public TableDataInfo list(ModbusJob modbusJob) {
|
||||
startPage();
|
||||
List<ModbusJob> list = modbusJobService.selectModbusJobList(modbusJob);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出轮训任务列列表
|
||||
*/
|
||||
@ApiOperation("导出轮训任务列列表")
|
||||
@PreAuthorize("@ss.hasPermi('modbus:job:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ModbusJob modbusJob) {
|
||||
List<ModbusJob> list = modbusJobService.selectModbusJobList(modbusJob);
|
||||
ExcelUtil<ModbusJob> util = new ExcelUtil<ModbusJob>(ModbusJob.class);
|
||||
util.exportExcel(response, list, "轮训任务列数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取轮训任务列详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:job:query')")
|
||||
@GetMapping(value = "/{taskId}")
|
||||
@ApiOperation("获取轮训任务列详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
|
||||
return success(modbusJobService.selectModbusJobByTaskId(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增轮训任务列
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:job:add')")
|
||||
@PostMapping
|
||||
@ApiOperation("新增轮训任务列")
|
||||
public AjaxResult add(@RequestBody ModbusJob modbusJob) {
|
||||
return toAjax(modbusJobService.insertModbusJob(modbusJob));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改轮训任务列
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:job:edit')")
|
||||
@PutMapping
|
||||
@ApiOperation("修改轮训任务列")
|
||||
public AjaxResult edit(@RequestBody ModbusJob modbusJob) {
|
||||
return toAjax(modbusJobService.updateModbusJob(modbusJob));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除轮训任务列
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:job:remove')")
|
||||
@PostMapping("/del")
|
||||
@ApiOperation("删除轮训任务列")
|
||||
public AjaxResult remove(@RequestBody ModbusJob modbusJob) throws SchedulerException {
|
||||
return toAjax(modbusJobService.deleteModbusJobByTaskId(modbusJob));
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.fastbee.data.controller.modbus;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.ModbusParams;
|
||||
import com.fastbee.iot.service.IModbusParamsService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 产品modbus配置参数Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-31
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/modbus/params")
|
||||
@Api(tags = "modbus配置参数")
|
||||
public class ModbusParamsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IModbusParamsService modbusParamsService;
|
||||
|
||||
/**
|
||||
* 查询产品modbus配置参数列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询产品modbus配置参数列表")
|
||||
public TableDataInfo list(ModbusParams modbusParams)
|
||||
{
|
||||
startPage();
|
||||
List<ModbusParams> list = modbusParamsService.selectModbusParamsList(modbusParams);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出产品modbus配置参数列表
|
||||
*/
|
||||
@ApiOperation("导出产品modbus配置参数列表")
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ModbusParams modbusParams)
|
||||
{
|
||||
List<ModbusParams> list = modbusParamsService.selectModbusParamsList(modbusParams);
|
||||
ExcelUtil<ModbusParams> util = new ExcelUtil<ModbusParams>(ModbusParams.class);
|
||||
util.exportExcel(response, list, "产品modbus配置参数数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品modbus配置参数详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取产品modbus配置参数详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(modbusParamsService.selectModbusParamsById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品modbus配置参数
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:add')")
|
||||
@PostMapping
|
||||
@ApiOperation("新增产品modbus配置参数")
|
||||
public AjaxResult add(@RequestBody ModbusParams modbusParams)
|
||||
{
|
||||
return toAjax(modbusParamsService.insertModbusParams(modbusParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品modbus配置参数
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:edit')")
|
||||
@PutMapping
|
||||
@ApiOperation("修改产品modbus配置参数")
|
||||
public AjaxResult edit(@RequestBody ModbusParams modbusParams)
|
||||
{
|
||||
return toAjax(modbusParamsService.updateModbusParams(modbusParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品modbus配置参数
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除产品modbus配置参数")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(modbusParamsService.deleteModbusParamsByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品io获取modbus配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('modbus:params:query')")
|
||||
@GetMapping(value = "/getByProductId")
|
||||
@ApiOperation("根据产品io获取modbus配置")
|
||||
public AjaxResult getByProductId(Long productId)
|
||||
{
|
||||
return success(modbusParamsService.getModbusParamsByProductId(productId));
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
package com.fastbee.data.controller.netty;
|
||||
|
||||
import com.fastbee.base.service.ISessionStore;
|
||||
import com.fastbee.base.session.Session;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.gateway.mq.Topics;
|
||||
import com.fastbee.mqtt.manager.ClientManager;
|
||||
import com.fastbee.mqtt.manager.SessionManger;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* NETTY客户端可视化
|
||||
*
|
||||
* @author gsb
|
||||
* @date 2023/3/23 14:51
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/mqtt")
|
||||
@Api(tags = "Netty可视化")
|
||||
@Slf4j
|
||||
public class NettyManagerController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ISessionStore sessionStore;
|
||||
|
||||
/**
|
||||
* 客户端管理列表
|
||||
* @param pageSize 分页大小
|
||||
* @param pageNum 页数
|
||||
* @param clientId 查询客户端id
|
||||
* @param serverCode 服务端类型编码 MQTT/TCP/UDP
|
||||
* @param isClient 是否只显示设备端 1-是/0或null-否
|
||||
* @return 客户端列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:emqx:client:list')")
|
||||
@GetMapping("/clients")
|
||||
@ApiOperation("netty客户端列表")
|
||||
public AjaxResult clients(Integer pageSize, Integer pageNum, String clientId, String serverCode,Integer isClient) {
|
||||
List<Session> list = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(clientId)) {
|
||||
ConcurrentHashMap<String, Session> sourceMap = sessionStore.getSessionMap();
|
||||
ConcurrentHashMap<String, Session> selectMap = new ConcurrentHashMap<>();
|
||||
sourceMap.forEach((key, value) -> {
|
||||
if (serverCode.equals(value.getServerType().getCode())) {
|
||||
if (null != isClient && isClient == 1){
|
||||
if (!key.startsWith("server") && !key.startsWith("web") && !key.startsWith("phone") && !key.startsWith("test")){
|
||||
selectMap.put(key,value);
|
||||
}
|
||||
}else {
|
||||
selectMap.put(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
Map<String, Session> sessionMap = sessionStore.listPage(selectMap, pageSize, pageNum);
|
||||
List<Session> result = new ArrayList<>(sessionMap.values());
|
||||
for (Session session : result) {
|
||||
Map<String, Boolean> topicMap = ClientManager.clientTopicMap.get(session.getClientId());
|
||||
if (topicMap != null) {
|
||||
List<Topics> topicsList = new ArrayList<>();
|
||||
topicMap.keySet().forEach(topic -> {
|
||||
Topics tBo = new Topics();
|
||||
tBo.setTopicName(topic);
|
||||
topicsList.add(tBo);
|
||||
});
|
||||
session.setTopics(topicsList);
|
||||
session.setTopicCount(topicMap.size());
|
||||
} else {
|
||||
session.setTopicCount(0);
|
||||
}
|
||||
list.add(session);
|
||||
}
|
||||
return AjaxResult.success(list, selectMap.size());
|
||||
} else {
|
||||
List<Session> result = new ArrayList<>();
|
||||
Session session = sessionStore.getSession(clientId);
|
||||
if (session != null) {
|
||||
Map<String, Boolean> topicMap = ClientManager.clientTopicMap.get(session.getClientId());
|
||||
if (topicMap != null) {
|
||||
List<Topics> topicsList = new ArrayList<>();
|
||||
topicMap.keySet().forEach(topic -> {
|
||||
Topics tBo = new Topics();
|
||||
tBo.setTopicName(topic);
|
||||
topicsList.add(tBo);
|
||||
});
|
||||
session.setTopics(topicsList);
|
||||
session.setTopicCount(topicMap.size());
|
||||
} else {
|
||||
session.setTopicCount(0);
|
||||
}
|
||||
if (serverCode.equals(session.getServerType().getCode())) {
|
||||
result.add(session);
|
||||
}
|
||||
}
|
||||
return AjaxResult.success(result, result.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('iot:emqx:client:remove')")
|
||||
@GetMapping("/client/out")
|
||||
@ApiOperation("netty客户端踢出")
|
||||
public AjaxResult clientOut(String clientId){
|
||||
Session session = sessionStore.getSession(clientId);
|
||||
Optional.ofNullable(session).orElseThrow(() -> new SecurityException(MessageUtils.message("netty.client.not.exists")));
|
||||
SessionManger.removeClient(clientId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.fastbee.data.controller.protocol;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.iot.domain.Protocol;
|
||||
import com.fastbee.iot.service.IProtocolService;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 协议Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2022-12-07
|
||||
*/
|
||||
@Api(tags = "协议")
|
||||
@RestController
|
||||
@RequestMapping("/iot/protocol")
|
||||
public class ProtocolController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IProtocolService protocolService;
|
||||
|
||||
/**
|
||||
* 查询协议列表
|
||||
*/
|
||||
@ApiOperation("查询协议列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:protocol:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(Protocol protocol)
|
||||
{
|
||||
startPage();
|
||||
List<Protocol> list = protocolService.selectProtocolList(protocol);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出协议列表
|
||||
*/
|
||||
@ApiOperation("导出协议列表")
|
||||
@PreAuthorize("@ss.hasPermi('iot:protocol:export')")
|
||||
@Log(title = "协议", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Protocol protocol)
|
||||
{
|
||||
List<Protocol> list = protocolService.selectProtocolList(protocol);
|
||||
ExcelUtil<Protocol> util = new ExcelUtil<Protocol>(Protocol.class);
|
||||
util.exportExcel(response, list, "协议数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取协议详细信息
|
||||
*/
|
||||
@ApiOperation("获取协议详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('iot:protocol:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return AjaxResult.success(protocolService.selectProtocolById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增协议
|
||||
*/
|
||||
@ApiOperation("新增协议")
|
||||
@PreAuthorize("@ss.hasPermi('iot:protocol:add')")
|
||||
@Log(title = "协议", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody Protocol protocol)
|
||||
{
|
||||
return toAjax(protocolService.insertProtocol(protocol));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改协议
|
||||
*/
|
||||
@ApiOperation("修改协议")
|
||||
@PreAuthorize("@ss.hasPermi('iot:protocol:edit')")
|
||||
@Log(title = "协议", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody Protocol protocol)
|
||||
{
|
||||
return toAjax(protocolService.updateProtocol(protocol));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除协议
|
||||
*/
|
||||
@ApiOperation("删除协议")
|
||||
@PreAuthorize("@ss.hasPermi('iot:protocol:remove')")
|
||||
@Log(title = "协议", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(protocolService.deleteProtocolByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
package com.fastbee.data.controller.runtime;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.mq.InvokeReqDto;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.data.service.IDeviceMessageService;
|
||||
import com.fastbee.iot.domain.FunctionLog;
|
||||
import com.fastbee.iot.domain.Scene;
|
||||
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem;
|
||||
import com.fastbee.iot.model.VariableReadVO;
|
||||
import com.fastbee.iot.service.IDeviceRuntimeService;
|
||||
import com.fastbee.iot.service.ISceneService;
|
||||
import com.fastbee.mq.ruleEngine.SceneContext;
|
||||
import com.fastbee.mq.service.IFunctionInvoke;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.fastbee.ruleEngine.core.FlowLogExecutor;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 设备运行时数据controller
|
||||
*
|
||||
* @author gsb
|
||||
* @date 2022/12/5 11:52
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/runtime")
|
||||
@Api(tags = "设备运行数据")
|
||||
public class DeviceRuntimeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IFunctionInvoke functionInvoke;
|
||||
@Resource
|
||||
private IDeviceRuntimeService runtimeService;
|
||||
@Resource
|
||||
private ISceneService sceneService;
|
||||
@Resource
|
||||
private IDeviceMessageService deviceMessageService;
|
||||
|
||||
@Autowired
|
||||
private FlowLogExecutor flowExecutor;
|
||||
|
||||
|
||||
/**
|
||||
* 服务下发返回回执
|
||||
*/
|
||||
@PostMapping(value = "/service/invokeReply")
|
||||
//@PreAuthorize("@ss.hasPermi('iot:service:invokereply')")
|
||||
@ApiOperation(value = "服务下发返回回执", httpMethod = "POST", response = AjaxResult.class, notes = "服务下发并返回回执")
|
||||
public AjaxResult invokeReply(@Valid @RequestBody InvokeReqDto reqDto) {
|
||||
reqDto.setParams(new JSONObject(reqDto.getRemoteCommand()));
|
||||
return functionInvoke.invokeReply(reqDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务下发
|
||||
* 例如modbus 格式如下
|
||||
*
|
||||
* @see InvokeReqDto#getRemoteCommand()
|
||||
* key = 寄存器地址
|
||||
* value = 寄存器地址值
|
||||
* <p>
|
||||
* 其他协议 key = identifier
|
||||
* value = 值
|
||||
* {
|
||||
* "serialNumber": "860061060282358",
|
||||
* "productId": "2",
|
||||
* "identifier": "temp",
|
||||
* "remoteCommand": {
|
||||
* "4": "4"
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
@PostMapping("/service/invoke")
|
||||
@PreAuthorize("@ss.hasPermi('iot:service:invoke')")
|
||||
@ApiOperation(value = "服务下发", httpMethod = "POST", response = AjaxResult.class, notes = "服务下发")
|
||||
public AjaxResult invoke(@Valid @RequestBody InvokeReqDto reqDto) {
|
||||
reqDto.setParams(new JSONObject(reqDto.getRemoteCommand()));
|
||||
return functionInvoke.invokeNoReply(reqDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行场景联动
|
||||
* @param sceneId 场景联动id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/runScene")
|
||||
@PreAuthorize("@ss.hasPermi('iot:scene:run')")
|
||||
@ApiOperation(value = "服务下发", httpMethod = "POST", response = AjaxResult.class, notes = "场景联动服务下发")
|
||||
public AjaxResult runScene(@RequestParam Long sceneId) throws ExecutionException, InterruptedException {
|
||||
if (sceneId == null) {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
System.out.println("------------------[执行一次场景联动]---------------------");
|
||||
Scene scene = sceneService.selectSceneBySceneId(sceneId);
|
||||
// 执行场景规则,异步非阻塞
|
||||
SceneContext context = new SceneContext("", 0L,0,null);
|
||||
flowExecutor.execute2Future(String.valueOf(scene.getChainName()), null, context);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 实时状态
|
||||
* @param serialNumber 设备编号
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping(value = "/running")
|
||||
@ApiOperation(value = "实时状态")
|
||||
public AjaxResult runState(String serialNumber){
|
||||
List<ThingsModelValueItem> valueItemList = runtimeService.runtimeBySerialNumber(serialNumber);
|
||||
return AjaxResult.success(valueItemList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据messageId查询服务回执
|
||||
*/
|
||||
@GetMapping(value = "fun/get")
|
||||
//@PreAuthorize("@ss.hasPermi('iot:service:get')")
|
||||
@ApiOperation(value = "根据messageId查询服务回执", httpMethod = "GET", response = AjaxResult.class, notes = "根据messageId查询服务回执")
|
||||
public AjaxResult reply(String serialNumber, String messageId) {
|
||||
if (StringUtils.isEmpty(messageId) || StringUtils.isEmpty(serialNumber)) {
|
||||
throw new ServiceException(MessageUtils.message("runtime.message.id.null"));
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备服务下发日志
|
||||
*/
|
||||
@GetMapping(value = "/funcLog")
|
||||
@ApiOperation(value = "设备服务下发日志")
|
||||
public TableDataInfo funcLog(String serialNumber){
|
||||
startPage();
|
||||
List<FunctionLog> logList = runtimeService.runtimeReply(serialNumber);
|
||||
return getDataTable(logList);
|
||||
}
|
||||
|
||||
@GetMapping(value = "prop/get")
|
||||
@ApiOperation(value = "主动采集", httpMethod = "GET", response = AjaxResult.class, notes = "主动采集")
|
||||
public AjaxResult propGet(VariableReadVO readVO){
|
||||
deviceMessageService.readVariableValue(readVO);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.fastbee.data.controller.sceneModel;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.SceneModel;
|
||||
import com.fastbee.iot.service.ISceneModelService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 场景管理Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/scene/model")
|
||||
@Api(tags = "场景管理")
|
||||
public class SceneModelController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ISceneModelService sceneModelService;
|
||||
|
||||
/**
|
||||
* 查询场景管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:model:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询场景管理列表")
|
||||
public TableDataInfo list(SceneModel sceneModel)
|
||||
{
|
||||
startPage();
|
||||
List<SceneModel> list = sceneModelService.selectSceneModelList(sceneModel);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出场景管理列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:model:export')")
|
||||
@Log(title = "场景管理", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出场景管理列表")
|
||||
public void export(HttpServletResponse response, SceneModel sceneModel)
|
||||
{
|
||||
List<SceneModel> list = sceneModelService.selectSceneModelList(sceneModel);
|
||||
ExcelUtil<SceneModel> util = new ExcelUtil<SceneModel>(SceneModel.class);
|
||||
util.exportExcel(response, list, "场景管理数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景管理详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:model:query')")
|
||||
@GetMapping(value = "/{sceneModelId}")
|
||||
@ApiOperation("获取场景管理详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("sceneModelId") Long sceneModelId)
|
||||
{
|
||||
return success(sceneModelService.selectSceneModelBySceneModelId(sceneModelId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增场景管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:model:add')")
|
||||
@Log(title = "场景管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增场景管理")
|
||||
public AjaxResult add(@RequestBody SceneModel sceneModel)
|
||||
{
|
||||
return toAjax(sceneModelService.insertSceneModel(sceneModel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:model:edit')")
|
||||
@Log(title = "场景管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改场景管理")
|
||||
public AjaxResult edit(@RequestBody SceneModel sceneModel)
|
||||
{
|
||||
return toAjax(sceneModelService.updateSceneModel(sceneModel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景管理
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:model:remove')")
|
||||
@Log(title = "场景管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{sceneModelIds}")
|
||||
@ApiOperation("删除场景管理")
|
||||
public AjaxResult remove(@PathVariable Long[] sceneModelIds)
|
||||
{
|
||||
return toAjax(sceneModelService.deleteSceneModelBySceneModelIds(sceneModelIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
package com.fastbee.data.controller.sceneModel;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.constant.HttpStatus;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataExtendInfo;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.enums.scenemodel.SceneModelVariableTypeEnum;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.SceneModelData;
|
||||
import com.fastbee.iot.model.scenemodel.SceneModelDataDTO;
|
||||
import com.fastbee.iot.service.ISceneModelDataService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-21
|
||||
*/
|
||||
@Api(tags = "场景变量管理")
|
||||
@RestController
|
||||
@RequestMapping("/scene/modelData")
|
||||
public class SceneModelDataController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ISceneModelDataService sceneModelDataService;
|
||||
|
||||
/**
|
||||
* 查询所有变量列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询所有变量列表")
|
||||
public TableDataInfo list(SceneModelData sceneModelData)
|
||||
{
|
||||
if (null == sceneModelData.getSceneModelId()) {
|
||||
throw new ServiceException("请传入场景管理id");
|
||||
}
|
||||
if (null == sceneModelData.getEnable()) {
|
||||
sceneModelData.setEnable(1);
|
||||
}
|
||||
Integer total = sceneModelDataService.countSceneModelDataList(sceneModelData);
|
||||
startPage();
|
||||
List<SceneModelDataDTO> list = sceneModelDataService.selectSceneModelDataDTOList(sceneModelData);
|
||||
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(list);
|
||||
rspData.setTotal(total);
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询关联设备变量的列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDeviceData:list')")
|
||||
@GetMapping("/listByType")
|
||||
@ApiOperation("查询关联设备变量的列表")
|
||||
public TableDataExtendInfo listByType(SceneModelData sceneModelData)
|
||||
{
|
||||
if (null == sceneModelData.getSceneModelId()
|
||||
&& !SceneModelVariableTypeEnum.THINGS_MODEL.getType().equals(sceneModelData.getVariableType())) {
|
||||
throw new ServiceException("请传入场景管理id");
|
||||
}
|
||||
return sceneModelDataService.listByType(sceneModelData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出【请填写功能名称】列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:export')")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出场景变量列表")
|
||||
public void export(HttpServletResponse response, SceneModelData sceneModelData)
|
||||
{
|
||||
List<SceneModelDataDTO> list = sceneModelDataService.selectSceneModelDataDTOList(sceneModelData);
|
||||
ExcelUtil<SceneModelDataDTO> util = new ExcelUtil<>(SceneModelDataDTO.class);
|
||||
util.exportExcel(response, list, "【请填写功能名称】数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取【请填写功能名称】详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取场景变量详情")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sceneModelDataService.selectSceneModelDataById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:add')")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增场景变量")
|
||||
public AjaxResult add(@RequestBody SceneModelData sceneModelData)
|
||||
{
|
||||
return toAjax(sceneModelDataService.insertSceneModelData(sceneModelData));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:edit')")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("编辑场景变量")
|
||||
public AjaxResult edit(@RequestBody SceneModelData sceneModelData)
|
||||
{
|
||||
return toAjax(sceneModelDataService.updateSceneModelData(sceneModelData));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:remove')")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除场景变量")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(sceneModelDataService.deleteSceneModelDataByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelData:editEnable')")
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/editEnable")
|
||||
@ApiOperation("编辑场景变量")
|
||||
public AjaxResult editEnable(@RequestBody SceneModelData sceneModelData)
|
||||
{
|
||||
return toAjax(sceneModelDataService.editEnable(sceneModelData));
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package com.fastbee.data.controller.sceneModel;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.enums.scenemodel.SceneModelVariableTypeEnum;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.SceneModelDevice;
|
||||
import com.fastbee.iot.service.ISceneModelDeviceService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 场景管理关联设备Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/scene/modelDevice")
|
||||
@Api(tags = "场景关联设备管理")
|
||||
public class SceneModelDeviceController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ISceneModelDeviceService sceneModelDeviceService;
|
||||
|
||||
/**
|
||||
* 查询场景管理关联设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询场景关联设备列表")
|
||||
public TableDataInfo list(SceneModelDevice sceneModelDevice)
|
||||
{
|
||||
startPage();
|
||||
List<SceneModelDevice> list = sceneModelDeviceService.selectSceneModelDeviceList(sceneModelDevice);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出场景管理关联设备列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:export')")
|
||||
@Log(title = "场景管理关联设备", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出场景关联设备列表")
|
||||
public void export(HttpServletResponse response, SceneModelDevice sceneModelDevice)
|
||||
{
|
||||
List<SceneModelDevice> list = sceneModelDeviceService.selectSceneModelDeviceList(sceneModelDevice);
|
||||
ExcelUtil<SceneModelDevice> util = new ExcelUtil<SceneModelDevice>(SceneModelDevice.class);
|
||||
util.exportExcel(response, list, "场景管理关联设备数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景管理关联设备详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("查询场景关联设备详情")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sceneModelDeviceService.selectSceneModelDeviceById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增场景管理关联设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:add')")
|
||||
@Log(title = "场景管理关联设备", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增场景关联设备")
|
||||
public AjaxResult add(@RequestBody SceneModelDevice sceneModelDevice)
|
||||
{
|
||||
if (null == sceneModelDevice.getSceneModelId()) {
|
||||
return AjaxResult.error("请传入场景id");
|
||||
}
|
||||
return toAjax(sceneModelDeviceService.insertSceneModelDevice(sceneModelDevice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景管理关联设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:edit')")
|
||||
@Log(title = "场景管理关联设备", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("编辑场景关联设备")
|
||||
public AjaxResult edit(@RequestBody SceneModelDevice sceneModelDevice)
|
||||
{
|
||||
if (null == sceneModelDevice.getSceneModelId()) {
|
||||
return AjaxResult.error("请传入场景id");
|
||||
}
|
||||
return toAjax(sceneModelDeviceService.updateSceneModelDevice(sceneModelDevice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景管理关联设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:edit')")
|
||||
@Log(title = "场景管理关联设备", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/editEnable")
|
||||
@ApiOperation("编辑场景关联设备")
|
||||
public AjaxResult editEnable(@RequestBody SceneModelDevice sceneModelDevice)
|
||||
{
|
||||
if (SceneModelVariableTypeEnum.THINGS_MODEL.getType().equals(sceneModelDevice.getVariableType())
|
||||
&& null == sceneModelDevice.getId()) {
|
||||
return AjaxResult.error("请传入关联设备配置的序号");
|
||||
}
|
||||
return toAjax(sceneModelDeviceService.editEnable(sceneModelDevice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景管理关联设备
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelDevice:remove')")
|
||||
@Log(title = "场景管理关联设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除场景关联设备")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(sceneModelDeviceService.deleteSceneModelDeviceByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package com.fastbee.data.controller.sceneModel;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.constant.HttpStatus;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.page.TableDataExtendInfo;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.iot.domain.SceneModelDevice;
|
||||
import com.fastbee.iot.domain.SceneModelTag;
|
||||
import com.fastbee.iot.mapper.SceneModelDataMapper;
|
||||
import com.fastbee.iot.service.ISceneModelDeviceService;
|
||||
import com.fastbee.iot.service.ISceneModelTagService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 场景录入型变量Controller
|
||||
*
|
||||
* @author kerwincui
|
||||
* @date 2024-05-21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/scene/modelTag")
|
||||
@Api(tags = "场景录入运算变量管理")
|
||||
public class SceneModelTagController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ISceneModelTagService sceneModelTagService;
|
||||
@Resource
|
||||
private ISceneModelDeviceService sceneModelDeviceService;
|
||||
@Resource
|
||||
private SceneModelDataMapper sceneModelDataMapper;
|
||||
|
||||
/**
|
||||
* 查询场景录入型变量列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelTag:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询场景录入运算变量列表")
|
||||
public TableDataExtendInfo list(SceneModelTag sceneModelTag)
|
||||
{
|
||||
SceneModelDevice sceneModelDevice = sceneModelDeviceService.selectOneBySceneModelIdAndVariableType(sceneModelTag.getSceneModelId(), sceneModelTag.getVariableType());
|
||||
startPage();
|
||||
List<SceneModelTag> list = sceneModelTagService.selectSceneModelTagList(sceneModelTag);
|
||||
TableDataExtendInfo rspData = new TableDataExtendInfo();
|
||||
rspData.setCode(HttpStatus.SUCCESS);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(list);
|
||||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
rspData.setAllEnable(null != sceneModelDevice ? sceneModelDevice.getAllEnable() : 0);
|
||||
return rspData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出场景录入型变量列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelTag:export')")
|
||||
@Log(title = "场景录入型变量", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出场景录入运算变量列表")
|
||||
public void export(HttpServletResponse response, SceneModelTag sceneModelTag)
|
||||
{
|
||||
List<SceneModelTag> list = sceneModelTagService.selectSceneModelTagList(sceneModelTag);
|
||||
ExcelUtil<SceneModelTag> util = new ExcelUtil<SceneModelTag>(SceneModelTag.class);
|
||||
util.exportExcel(response, list, "场景录入型变量数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景录入型变量详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelTag:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取场景录入运算变量详情")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sceneModelTagService.selectSceneModelTagById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增场景录入型变量
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelTag:add')")
|
||||
@Log(title = "场景录入型变量", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增场景录入运算变量")
|
||||
public AjaxResult add(@RequestBody SceneModelTag sceneModelTag)
|
||||
{
|
||||
return toAjax(sceneModelTagService.insertSceneModelTag(sceneModelTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改场景录入型变量
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelTag:edit')")
|
||||
@Log(title = "场景录入型变量", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("编辑场景录入运算变量")
|
||||
public AjaxResult edit(@RequestBody SceneModelTag sceneModelTag)
|
||||
{
|
||||
return toAjax(sceneModelTagService.updateSceneModelTag(sceneModelTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景录入型变量
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('scene:modelTag:remove')")
|
||||
@Log(title = "场景录入型变量", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除场景录入运算变量")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
// 校验场景是否被应用到计算公式
|
||||
int count = sceneModelDataMapper.checkIsApplyAliasFormule(ids[0], null);
|
||||
if (count > 0) {
|
||||
throw new ServiceException("当前变量被引用到场景运算型变量的计算公式中,无法删除,请先删除引用关系后再执行删除操作!");
|
||||
}
|
||||
return toAjax(sceneModelTagService.deleteSceneModelTagByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.fastbee.data.controller.translate;
|
||||
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.CommonResult;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.system.domain.AppLanguage;
|
||||
import com.fastbee.system.service.IAppLanguageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* app语言Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/app/language")
|
||||
@Api(tags = "APP语言")
|
||||
public class AppLanguageController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IAppLanguageService appLanguageService;
|
||||
|
||||
/**
|
||||
* 查询app语言列表
|
||||
*/
|
||||
//@PreAuthorize("@ss.hasPermi('app:language:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询app语言列表")
|
||||
public TableDataInfo list(AppLanguage appLanguage)
|
||||
{
|
||||
startPage();
|
||||
List<AppLanguage> list = appLanguageService.selectAppLanguageList(appLanguage);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出app语言列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('app:language:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, AppLanguage appLanguage)
|
||||
{
|
||||
List<AppLanguage> list = appLanguageService.selectAppLanguageList(appLanguage);
|
||||
ExcelUtil<AppLanguage> util = new ExcelUtil<AppLanguage>(AppLanguage.class);
|
||||
util.exportExcel(response, list, "app语言数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取app语言详细信息
|
||||
*/
|
||||
//@PreAuthorize("@ss.hasPermi('app:language:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiOperation("获取app语言详细信息")
|
||||
public CommonResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return CommonResult.success(appLanguageService.selectAppLanguageById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增app语言
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('app:language:add')")
|
||||
@PostMapping
|
||||
public CommonResult add(@RequestBody AppLanguage appLanguage)
|
||||
{
|
||||
return CommonResult.success(appLanguageService.insertAppLanguage(appLanguage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改app语言
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('app:language:edit')")
|
||||
@PutMapping
|
||||
public CommonResult edit(@RequestBody AppLanguage appLanguage)
|
||||
{
|
||||
return CommonResult.success(appLanguageService.updateAppLanguage(appLanguage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除app语言
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('app:language:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
public CommonResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return CommonResult.success(appLanguageService.deleteAppLanguageByIds(ids));
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package com.fastbee.data.controller.translate;
|
||||
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.CommonResult;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.core.page.TableDataInfo;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||
import com.fastbee.framework.web.service.TokenService;
|
||||
import com.fastbee.system.domain.AppPreferences;
|
||||
import com.fastbee.system.service.IAppPreferencesService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* APP用户偏好设置Controller
|
||||
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/app/preferences")
|
||||
@Api(tags = "APP用户偏好设置")
|
||||
public class AppPreferencesController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private IAppPreferencesService appPreferencesService;
|
||||
|
||||
@Resource
|
||||
private TokenService tokenService;
|
||||
|
||||
/**
|
||||
* 查询APP用户偏好设置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:preferences:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(AppPreferences appPreferences)
|
||||
{
|
||||
startPage();
|
||||
List<AppPreferences> list = appPreferencesService.selectAppPreferencesList(appPreferences);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出APP用户偏好设置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:preferences:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, AppPreferences appPreferences)
|
||||
{
|
||||
List<AppPreferences> list = appPreferencesService.selectAppPreferencesList(appPreferences);
|
||||
ExcelUtil<AppPreferences> util = new ExcelUtil<AppPreferences>(AppPreferences.class);
|
||||
util.exportExcel(response, list, "APP用户偏好设置数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取APP用户偏好设置详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:preferences:query')")
|
||||
@GetMapping(value = "/{userId}")
|
||||
public CommonResult getInfo(@PathVariable("userId") Long userId)
|
||||
{
|
||||
if (userId == null) {
|
||||
userId = SecurityUtils.getUserId();
|
||||
}
|
||||
return CommonResult.success(appPreferencesService.selectAppPreferencesByUserId(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增APP用户偏好设置
|
||||
*/
|
||||
//@PreAuthorize("@ss.hasPermi('iot:preferences:add')")
|
||||
@PostMapping("/addOrUpdate")
|
||||
@ApiOperation("新增或者更新APP用户偏好设置")
|
||||
public CommonResult add(@RequestBody AppPreferences appPreferences)
|
||||
{
|
||||
LoginUser loginUser = getLoginUser();
|
||||
loginUser.setLanguage(appPreferences.getLanguage());
|
||||
tokenService.setLoginUser(loginUser);
|
||||
return CommonResult.success(appPreferencesService.addOrUpdate(appPreferences));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改APP用户偏好设置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:preferences:edit')")
|
||||
@PutMapping
|
||||
public CommonResult edit(@RequestBody AppPreferences appPreferences)
|
||||
{
|
||||
return CommonResult.success(appPreferencesService.updateAppPreferences(appPreferences));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除APP用户偏好设置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:preferences:remove')")
|
||||
@DeleteMapping("/{userIds}")
|
||||
public CommonResult remove(@PathVariable Long[] userIds)
|
||||
{
|
||||
return CommonResult.success(appPreferencesService.deleteAppPreferencesByUserIds(userIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package com.fastbee.data.controller.wechat;
|
||||
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.sign.SignUtils;
|
||||
import com.fastbee.common.wechat.WeChatLoginBody;
|
||||
import com.fastbee.common.wechat.WeChatLoginResult;
|
||||
import com.fastbee.iot.wechat.WeChatService;
|
||||
import com.fastbee.iot.wechat.vo.WxBindReqVO;
|
||||
import com.fastbee.iot.wechat.vo.WxCancelBindReqVO;
|
||||
import com.fastbee.iot.wechat.WeChatCallbackService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import static com.fastbee.common.constant.Constants.LANGUAGE;
|
||||
|
||||
/**
|
||||
* 微信相关控制器
|
||||
* @author fastb
|
||||
* @date 2023-07-31 11:29
|
||||
*/
|
||||
@Api(tags = "微信相关模块")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wechat")
|
||||
public class WeChatController {
|
||||
|
||||
@Resource
|
||||
private WeChatService weChatService;
|
||||
@Resource
|
||||
private WeChatCallbackService weChatCallbackService;
|
||||
|
||||
/**
|
||||
* 移动应用微信登录
|
||||
* @param weChatLoginBody 微信登录参数
|
||||
* @return 登录结果
|
||||
*/
|
||||
@ApiOperation("移动应用微信登录")
|
||||
@PostMapping("/mobileLogin")
|
||||
public AjaxResult mobileLogin(HttpServletRequest request, @RequestBody WeChatLoginBody weChatLoginBody) {
|
||||
return AjaxResult.success(weChatService.mobileLogin(weChatLoginBody, request.getHeader(LANGUAGE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序微信登录
|
||||
* @param weChatLoginBody 微信登录参数
|
||||
* @return 登录结果
|
||||
*/
|
||||
@ApiOperation("小程序微信登录")
|
||||
@PostMapping("/miniLogin")
|
||||
public AjaxResult miniLogin(HttpServletRequest request, @RequestBody WeChatLoginBody weChatLoginBody) {
|
||||
WeChatLoginResult weChatLoginResult = weChatService.miniLogin(weChatLoginBody, request.getHeader(LANGUAGE));
|
||||
return AjaxResult.success(weChatLoginResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序、移动应用微信绑定
|
||||
* @param wxBindReqVO 微信绑定传参类型
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation("小程序、移动应用微信绑定")
|
||||
@PostMapping("/bind")
|
||||
public AjaxResult bind(@RequestBody WxBindReqVO wxBindReqVO) {
|
||||
if (StringUtils.isEmpty(wxBindReqVO.getSourceClient())) {
|
||||
throw new ServiceException(MessageUtils.message("wechat.verify.type.null"));
|
||||
}
|
||||
return weChatService.bind(wxBindReqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消所有微信绑定
|
||||
* @param wxCancelBindReqVO 微信解绑传参类型
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation("取消所有微信绑定")
|
||||
@PostMapping("/cancelBind")
|
||||
public AjaxResult cancelBind(@RequestBody WxCancelBindReqVO wxCancelBindReqVO) {
|
||||
if (wxCancelBindReqVO.getVerifyType() == null) {
|
||||
throw new ServiceException(MessageUtils.message("wechat.verify.type.null"));
|
||||
}
|
||||
return weChatService.cancelBind(wxCancelBindReqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 网站应用获取微信绑定二维码信息
|
||||
* @return 二维码信息
|
||||
*/
|
||||
@ApiOperation("网站应用获取微信绑定二维码信息")
|
||||
@GetMapping("/getWxBindQr")
|
||||
public AjaxResult getWxBindQr(HttpServletRequest httpServletRequest) {
|
||||
// 返回二维码信息
|
||||
return weChatService.getWxBindQr(httpServletRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 网站应用内微信扫码绑定回调接口
|
||||
* @param code 用户凭证
|
||||
* @param state 时间戳
|
||||
* @param httpServletRequest 请求信息
|
||||
* @param httpServletResponse 响应信息
|
||||
*/
|
||||
@ApiOperation("网站应用内微信扫码绑定回调地址")
|
||||
@GetMapping("/wxBind/callback")
|
||||
public void wxBindCallback(String code, String state, String wxBindId, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
|
||||
//回调接口
|
||||
httpServletResponse.sendRedirect(weChatService.wxBindCallback(code, state, wxBindId, httpServletRequest, httpServletResponse));
|
||||
}
|
||||
|
||||
/**
|
||||
* 网站应用获取微信绑定结果信息
|
||||
* @param wxBindMsgId 微信绑定结果信息id
|
||||
* @return msg
|
||||
*/
|
||||
@ApiOperation("网站应用获取微信绑定结果信息")
|
||||
@GetMapping("/getWxBindMsg")
|
||||
public AjaxResult getWxBindMsg(String wxBindMsgId) {
|
||||
if (StringUtils.isEmpty(wxBindMsgId)) {
|
||||
return AjaxResult.error(MessageUtils.message("wechat.bind.message.id.null"));
|
||||
}
|
||||
// 返回二维码信息
|
||||
return weChatService.getWxBindMsg(wxBindMsgId);
|
||||
}
|
||||
|
||||
@ApiOperation("微信公众号验证url")
|
||||
@GetMapping("/publicAccount/callback")
|
||||
public void checkUrl(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
// 微信加密签名
|
||||
String signature = request.getParameter("signature");
|
||||
// 时间戳
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
// 随机数
|
||||
String nonce = request.getParameter("nonce");
|
||||
// 随机字符串
|
||||
String echostr = request.getParameter("echostr");
|
||||
// token
|
||||
String token = "fastbee";
|
||||
boolean check = SignUtils.checkSignature(token, signature, timestamp, nonce);
|
||||
PrintWriter writer = response.getWriter();
|
||||
if (check) {
|
||||
writer.print(echostr);
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@ApiOperation("微信公众号回调")
|
||||
@PostMapping("/publicAccount/callback")
|
||||
public void publicAccountCallback(@RequestBody final String xmlStr, HttpServletResponse response){
|
||||
log.info("微信回调接口调用入参:{}", xmlStr);
|
||||
final String responseStr = weChatCallbackService.handleCallback(xmlStr);
|
||||
log.info("微信回调接口调用返回:入参xmlStr:{},responseStr:{}", xmlStr, responseStr);
|
||||
if (StringUtils.isEmpty(responseStr) || "success".equals(responseStr)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
response.setHeader("Content-type", "textml;charset=UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.getWriter().write(responseStr);
|
||||
} catch (final IOException e) {
|
||||
log.error("微信回调回复信息回写失败:xmlStr:{},responseStr:{},e:{}", xmlStr, responseStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.fastbee.data.quartz;
|
||||
|
||||
import com.fastbee.common.constant.Constants;
|
||||
import com.fastbee.common.constant.ScheduleConstants;
|
||||
import com.fastbee.common.utils.ExceptionUtil;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.bean.BeanUtils;
|
||||
import com.fastbee.common.utils.spring.SpringUtils;
|
||||
import com.fastbee.iot.domain.DeviceJob;
|
||||
import com.fastbee.quartz.domain.SysJobLog;
|
||||
import com.fastbee.quartz.service.ISysJobLogService;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 抽象quartz调用
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public abstract class AbstractQuartzJob implements Job
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
|
||||
|
||||
/**
|
||||
* 线程本地变量
|
||||
*/
|
||||
private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||
{
|
||||
DeviceJob deviceJob = new DeviceJob();
|
||||
BeanUtils.copyBeanProp(deviceJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
||||
try
|
||||
{
|
||||
before(context, deviceJob);
|
||||
if (deviceJob != null)
|
||||
{
|
||||
doExecute(context, deviceJob);
|
||||
}
|
||||
after(context, deviceJob, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("任务执行异常 - :", e);
|
||||
after(context, deviceJob, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行前
|
||||
*
|
||||
* @param context 工作执行上下文对象
|
||||
* @param deviceJob 系统计划任务
|
||||
*/
|
||||
protected void before(JobExecutionContext context, DeviceJob deviceJob)
|
||||
{
|
||||
threadLocal.set(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行后
|
||||
*
|
||||
* @param context 工作执行上下文对象
|
||||
* @param deviceJob 系统计划任务
|
||||
*/
|
||||
protected void after(JobExecutionContext context, DeviceJob deviceJob, Exception e)
|
||||
{
|
||||
Date startTime = threadLocal.get();
|
||||
threadLocal.remove();
|
||||
|
||||
final SysJobLog sysJobLog = new SysJobLog();
|
||||
sysJobLog.setJobName(deviceJob.getJobName());
|
||||
sysJobLog.setJobGroup(deviceJob.getJobGroup());
|
||||
sysJobLog.setInvokeTarget(deviceJob.getDeviceName());
|
||||
sysJobLog.setStartTime(startTime);
|
||||
sysJobLog.setStopTime(new Date());
|
||||
long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
|
||||
sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
|
||||
if (e != null)
|
||||
{
|
||||
sysJobLog.setStatus(Constants.FAIL);
|
||||
String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
|
||||
sysJobLog.setExceptionInfo(errorMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
sysJobLog.setStatus(Constants.SUCCESS);
|
||||
}
|
||||
|
||||
// 写入数据库当中
|
||||
SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行方法,由子类重载
|
||||
*
|
||||
* @param context 工作执行上下文对象
|
||||
* @param deviceJob 系统计划任务
|
||||
* @throws Exception 执行过程中的异常
|
||||
*/
|
||||
protected abstract void doExecute(JobExecutionContext context, DeviceJob deviceJob) throws Exception;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.fastbee.data.quartz;
|
||||
|
||||
import org.quartz.CronExpression;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* cron表达式工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
public class CronUtils
|
||||
{
|
||||
/**
|
||||
* 返回一个布尔值代表一个给定的Cron表达式的有效性
|
||||
*
|
||||
* @param cronExpression Cron表达式
|
||||
* @return boolean 表达式是否有效
|
||||
*/
|
||||
public static boolean isValid(String cronExpression)
|
||||
{
|
||||
return CronExpression.isValidExpression(cronExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个字符串值,表示该消息无效Cron表达式给出有效性
|
||||
*
|
||||
* @param cronExpression Cron表达式
|
||||
* @return String 无效时返回表达式错误描述,如果有效返回null
|
||||
*/
|
||||
public static String getInvalidMessage(String cronExpression)
|
||||
{
|
||||
try
|
||||
{
|
||||
new CronExpression(cronExpression);
|
||||
return null;
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
return pe.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回下一个执行时间根据给定的Cron表达式
|
||||
*
|
||||
* @param cronExpression Cron表达式
|
||||
* @return Date 下次Cron表达式执行时间
|
||||
*/
|
||||
public static Date getNextExecution(String cronExpression)
|
||||
{
|
||||
try
|
||||
{
|
||||
CronExpression cron = new CronExpression(cronExpression);
|
||||
return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
throw new IllegalArgumentException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package com.fastbee.data.quartz;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.fastbee.base.service.ISessionStore;
|
||||
import com.fastbee.base.session.Session;
|
||||
import com.fastbee.common.core.device.DeviceAndProtocol;
|
||||
import com.fastbee.common.core.mq.message.ModbusPollMsg;
|
||||
import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
|
||||
import com.fastbee.common.enums.DeviceStatus;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.spring.SpringUtils;
|
||||
import com.fastbee.iot.domain.*;
|
||||
import com.fastbee.iot.enums.DeviceType;
|
||||
import com.fastbee.iot.mapper.*;
|
||||
import com.fastbee.iot.model.Action;
|
||||
import com.fastbee.iot.model.DeviceStatusVO;
|
||||
import com.fastbee.iot.model.ModbusJobBo;
|
||||
import com.fastbee.iot.model.ModbusPollBo;
|
||||
import com.fastbee.iot.service.*;
|
||||
import com.fastbee.mq.redischannel.producer.MessageProducer;
|
||||
import com.fastbee.mq.ruleEngine.SceneContext;
|
||||
import com.fastbee.mq.service.IDataHandler;
|
||||
import com.fastbee.mq.service.IMqttMessagePublish;
|
||||
import com.fastbee.mqtt.manager.MqttRemoteManager;
|
||||
import com.fastbee.ruleEngine.core.FlowLogExecutor;
|
||||
import com.google.common.annotations.GwtCompatible;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 任务执行工具
|
||||
*
|
||||
* @author kerwincui
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobInvokeUtil {
|
||||
|
||||
/**
|
||||
* 获取消息推送接口
|
||||
*/
|
||||
private static IMqttMessagePublish messagePublish = SpringUtils.getBean(IMqttMessagePublish.class);
|
||||
|
||||
private static SceneMapper sceneMapper = SpringUtils.getBean(SceneMapper.class);
|
||||
|
||||
private static FlowLogExecutor flowExecutor = SpringUtils.getBean(FlowLogExecutor.class);
|
||||
|
||||
private static IDataHandler dataHandler = SpringUtils.getBean(IDataHandler.class);
|
||||
|
||||
private static IDeviceService deviceService = SpringUtils.getBean(IDeviceService.class);
|
||||
|
||||
private static IModbusJobService modbusJobService = SpringUtils.getBean(IModbusJobService.class);
|
||||
|
||||
private static IModbusParamsService modbusParamsService = SpringUtils.getBean(IModbusParamsService.class);
|
||||
|
||||
private static ISessionStore sessionStore = SpringUtils.getBean(ISessionStore.class);
|
||||
|
||||
private static MqttRemoteManager mqttRemoteManager = SpringUtils.getBean(MqttRemoteManager.class);
|
||||
|
||||
/**
|
||||
* 执行方法
|
||||
*
|
||||
* @param deviceJob 系统任务
|
||||
*/
|
||||
public static void invokeMethod(DeviceJob deviceJob) throws Exception {
|
||||
if (deviceJob.getJobType() == 1) {
|
||||
System.out.println("------------------------执行定时任务-----------------------------");
|
||||
List<Action> actions = JSON.parseArray(deviceJob.getActions(), Action.class);
|
||||
List<ThingsModelSimpleItem> propertys = new ArrayList<>();
|
||||
List<ThingsModelSimpleItem> functions = new ArrayList<>();
|
||||
for (int i = 0; i < actions.size(); i++) {
|
||||
ThingsModelSimpleItem model = new ThingsModelSimpleItem();
|
||||
model.setId(actions.get(i).getId());
|
||||
model.setValue(actions.get(i).getValue());
|
||||
model.setRemark("设备定时");
|
||||
if (actions.get(i).getType() == 1) {
|
||||
propertys.add(model);
|
||||
} else if (actions.get(i).getType() == 2) {
|
||||
functions.add(model);
|
||||
}
|
||||
}
|
||||
// 发布属性
|
||||
if (propertys.size() > 0) {
|
||||
messagePublish.publishProperty(deviceJob.getProductId(), deviceJob.getSerialNumber(), propertys, 0);
|
||||
}
|
||||
// 发布功能
|
||||
if (functions.size() > 0) {
|
||||
messagePublish.publishFunction(deviceJob.getProductId(), deviceJob.getSerialNumber(), functions, 0);
|
||||
}
|
||||
|
||||
} else if (deviceJob.getJobType() == 3) {
|
||||
System.out.println("------------------[定时执行场景联动]---------------------");
|
||||
Scene scene=sceneMapper.selectSceneBySceneId(deviceJob.getSceneId());
|
||||
// 执行场景规则,异步非阻塞
|
||||
SceneContext context = new SceneContext("", 0L,0,null);
|
||||
flowExecutor.execute2Future(String.valueOf(scene.getChainName()), null, context);
|
||||
} else if (4 == deviceJob.getJobType()) {
|
||||
System.out.println("------------------[定时执行场景运算型变量]---------------------");
|
||||
String s = dataHandler.calculateSceneModelTagValue(deviceJob.getDatasourceId());
|
||||
if (StringUtils.isEmpty(s)) {
|
||||
System.out.println("------------------[定时执行场景运算型变量失败:+" + s + "]---------------------");
|
||||
}
|
||||
}else if (5 == deviceJob.getJobType()){
|
||||
log.info("----------------执行modbus轮训指令----------------------");
|
||||
Long jobId = deviceJob.getJobId();
|
||||
ModbusJob modbusJob = new ModbusJob();
|
||||
modbusJob.setJobId(jobId);
|
||||
modbusJob.setStatus("0");
|
||||
List<ModbusJob> modbusJobList = modbusJobService.selectModbusJobList(modbusJob);
|
||||
if (CollectionUtils.isEmpty(modbusJobList))return;
|
||||
//处理子设备情况
|
||||
handleSubDeviceStatus(modbusJobList);
|
||||
List<String> commandList = modbusJobList.stream().map(ModbusJob::getCommand).collect(Collectors.toList());
|
||||
ModbusPollMsg modbusPollMsg = new ModbusPollMsg();
|
||||
modbusPollMsg.setSerialNumber(deviceJob.getSerialNumber());
|
||||
modbusPollMsg.setProductId(deviceJob.getProductId());
|
||||
modbusPollMsg.setCommandList(commandList);
|
||||
DeviceStatusVO deviceStatusVO = deviceService.selectDeviceStatusAndTransportStatus(modbusPollMsg.getSerialNumber());
|
||||
modbusPollMsg.setTransport(deviceStatusVO.getTransport());
|
||||
if (deviceStatusVO.getStatus() != DeviceStatus.ONLINE.getType()){
|
||||
log.info("设备:[{}],不在线",modbusPollMsg.getSerialNumber());
|
||||
return;
|
||||
}
|
||||
log.info("执行modbus轮询指令:[{}]",JSON.toJSONString(commandList));
|
||||
MessageProducer.sendPropFetch(modbusPollMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO --耗时操作,这里后续放在MQ处理
|
||||
* 处理子设备根据设备数据定时更新状态
|
||||
*/
|
||||
public static void handleSubDeviceStatus(List<ModbusJob> modbusJobList){
|
||||
for (ModbusJob modbusJob : modbusJobList) {
|
||||
String subSerialNumber = modbusJob.getSubSerialNumber();
|
||||
Session session = sessionStore.getSession(subSerialNumber);
|
||||
if (Objects.isNull(session))continue;
|
||||
//如果是网关子设备,则检测子设备是否在特定时间内有数据上报
|
||||
if (modbusJob.getDeviceType() == DeviceType.SUB_GATEWAY.getCode()){
|
||||
long deterTime = 300L; //这里默认使用5分钟,如果轮询时间大于5分钟,请在配置参数设置更长时间
|
||||
ModbusParams params = modbusParamsService.getModbusParamsByDeviceId(modbusJob.getSubDeviceId());
|
||||
if (!Objects.isNull(params)){
|
||||
deterTime = Long.parseLong(params.getDeterTimer());
|
||||
}
|
||||
|
||||
long lastAccessTime = session.getLastAccessTime();
|
||||
//如果现在的时间 - 最后访问时间 > 判断时间则更新为离线
|
||||
long time = (System.currentTimeMillis() - lastAccessTime) / 1000;
|
||||
if (time > deterTime){
|
||||
//处理设备离线
|
||||
Device updateBo = new Device();
|
||||
updateBo.setStatus(DeviceStatus.OFFLINE.getType());
|
||||
updateBo.setSerialNumber(subSerialNumber);
|
||||
updateBo.setUpdateTime(DateUtils.getNowDate());
|
||||
deviceService.updateDeviceStatus(updateBo);
|
||||
mqttRemoteManager.pushDeviceStatus(params.getProductId(), subSerialNumber, DeviceStatus.OFFLINE);
|
||||
sessionStore.cleanSession(subSerialNumber);
|
||||
log.info("设备[{}],超过:[{}],未上报数据,更新为离线",subSerialNumber,deterTime);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.fastbee.data.quartz;
|
||||
|
||||
import com.fastbee.iot.domain.DeviceJob;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
/**
|
||||
* 定时任务处理(禁止并发执行)
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
@DisallowConcurrentExecution
|
||||
public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob
|
||||
{
|
||||
@Override
|
||||
protected void doExecute(JobExecutionContext context, DeviceJob deviceJob) throws Exception
|
||||
{
|
||||
JobInvokeUtil.invokeMethod(deviceJob);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.fastbee.data.quartz;
|
||||
|
||||
import com.fastbee.iot.domain.DeviceJob;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
/**
|
||||
* 定时任务处理(允许并发执行)
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
public class QuartzJobExecution extends AbstractQuartzJob
|
||||
{
|
||||
@Override
|
||||
protected void doExecute(JobExecutionContext context, DeviceJob deviceJob) throws Exception
|
||||
{
|
||||
JobInvokeUtil.invokeMethod(deviceJob);
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.fastbee.data.quartz;
|
||||
|
||||
import com.fastbee.common.constant.ScheduleConstants;
|
||||
import com.fastbee.common.exception.job.TaskException;
|
||||
import com.fastbee.common.exception.job.TaskException.Code;
|
||||
import com.fastbee.iot.domain.DeviceJob;
|
||||
import org.quartz.*;
|
||||
|
||||
/**
|
||||
* 定时任务工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*
|
||||
*/
|
||||
public class ScheduleUtils
|
||||
{
|
||||
/**
|
||||
* 得到quartz任务类
|
||||
*
|
||||
* @param deviceJob 执行计划
|
||||
* @return 具体执行任务类
|
||||
*/
|
||||
private static Class<? extends Job> getQuartzJobClass(DeviceJob deviceJob)
|
||||
{
|
||||
boolean isConcurrent = "0".equals(deviceJob.getConcurrent());
|
||||
return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建任务触发对象
|
||||
*/
|
||||
public static TriggerKey getTriggerKey(Long jobId, String jobGroup)
|
||||
{
|
||||
return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建任务键对象
|
||||
*/
|
||||
public static JobKey getJobKey(Long jobId, String jobGroup)
|
||||
{
|
||||
return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建定时任务
|
||||
*/
|
||||
public static void createScheduleJob(Scheduler scheduler, DeviceJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
Class<? extends Job> jobClass = getQuartzJobClass(job);
|
||||
// 1.创建任务
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();
|
||||
|
||||
// 表达式调度构建器
|
||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
|
||||
cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
|
||||
|
||||
// 2.创建触发器, 按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup))
|
||||
.withSchedule(cronScheduleBuilder).build();
|
||||
|
||||
// 放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
|
||||
|
||||
// 判断是否存在
|
||||
if (scheduler.checkExists(getJobKey(jobId, jobGroup)))
|
||||
{
|
||||
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
||||
scheduler.deleteJob(getJobKey(jobId, jobGroup));
|
||||
}
|
||||
|
||||
// 3.任务和触发器添加到调度器
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
|
||||
// 暂停任务
|
||||
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
|
||||
{
|
||||
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置定时任务策略
|
||||
*/
|
||||
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(DeviceJob job, CronScheduleBuilder cb)
|
||||
throws TaskException
|
||||
{
|
||||
switch (job.getMisfirePolicy())
|
||||
{
|
||||
case ScheduleConstants.MISFIRE_DEFAULT:
|
||||
return cb;
|
||||
case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
|
||||
return cb.withMisfireHandlingInstructionIgnoreMisfires();
|
||||
case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
|
||||
return cb.withMisfireHandlingInstructionFireAndProceed();
|
||||
case ScheduleConstants.MISFIRE_DO_NOTHING:
|
||||
return cb.withMisfireHandlingInstructionDoNothing();
|
||||
default:
|
||||
throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
|
||||
+ "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.fastbee.data.service;
|
||||
|
||||
import com.fastbee.common.core.mq.message.DeviceMessage;
|
||||
import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
|
||||
import com.fastbee.iot.model.VariableReadVO;
|
||||
import com.fastbee.modbus.model.ModbusRtu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备消息Service接口
|
||||
*/
|
||||
public interface IDeviceMessageService {
|
||||
|
||||
void messagePost(DeviceMessage deviceMessage);
|
||||
|
||||
String messageEncode(ModbusRtu modbusRtu);
|
||||
|
||||
List<ThingsModelSimpleItem> messageDecode(DeviceMessage deviceMessage);
|
||||
|
||||
|
||||
/**
|
||||
* 变量读取
|
||||
* @param readVO
|
||||
*/
|
||||
public void readVariableValue(VariableReadVO readVO);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.fastbee.data.service;
|
||||
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeDelayTask;
|
||||
|
||||
/**
|
||||
* OTA升级
|
||||
* @author bill
|
||||
*/
|
||||
public interface IOtaUpgradeService {
|
||||
|
||||
/**
|
||||
* OTA延迟升级任务发送
|
||||
* @param task
|
||||
*/
|
||||
public void upgrade(OtaUpgradeDelayTask task);
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.fastbee.data.service;
|
||||
|
||||
import com.fastbee.base.session.Session;
|
||||
import com.fastbee.common.enums.DeviceStatus;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.model.DeviceStatusVO;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import com.fastbee.iot.service.IProductService;
|
||||
import com.fastbee.mqtt.manager.MqttRemoteManager;
|
||||
import com.fastbee.mqtt.manager.SessionManger;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 定时同步设备状态 -- netty版本mqtt使用
|
||||
* @author gsb
|
||||
* @date 2024/4/11 10:33
|
||||
*/
|
||||
@Component
|
||||
public class SyncDeviceStatusJob {
|
||||
|
||||
@Resource
|
||||
private IDeviceService deviceService;
|
||||
@Resource
|
||||
private MqttRemoteManager mqttRemoteManager;
|
||||
@Value("${server.broker.enabled}")
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 定期同步设备状态
|
||||
* 1.将异常在线设备变更为离线状态
|
||||
* 2.将离线设备但实际在线设备变更为在线
|
||||
*/
|
||||
public void syncDeviceStatus() {
|
||||
if (enabled) {
|
||||
//获取所有已激活并不是禁用的设备
|
||||
List<DeviceStatusVO> deviceStatusVOList = deviceService.selectDeviceActive();
|
||||
if (!CollectionUtils.isEmpty(deviceStatusVOList)) {
|
||||
for (DeviceStatusVO statusVO : deviceStatusVOList) {
|
||||
Session session = SessionManger.getSession(statusVO.getSerialNumber());
|
||||
//以session为准
|
||||
// 如果session中设备在线,数据库状态离线 ,则更新设备的状态为在线
|
||||
if (!Objects.isNull(session) && statusVO.getStatus() == DeviceStatus.OFFLINE.getType()) {
|
||||
Device device = new Device();
|
||||
device.setStatus(DeviceStatus.ONLINE.getType());
|
||||
device.setSerialNumber(statusVO.getSerialNumber());
|
||||
deviceService.updateDeviceStatus(device);
|
||||
mqttRemoteManager.pushDeviceStatus(-1L, statusVO.getSerialNumber(), DeviceStatus.ONLINE);
|
||||
}
|
||||
if (Objects.isNull(session) && statusVO.getStatus() == DeviceStatus.ONLINE.getType()) {
|
||||
Device device = new Device();
|
||||
device.setStatus(DeviceStatus.OFFLINE.getType());
|
||||
device.setSerialNumber(statusVO.getSerialNumber());
|
||||
deviceService.updateDeviceStatus(device);
|
||||
mqttRemoteManager.pushDeviceStatus(-1L, statusVO.getSerialNumber(), DeviceStatus.OFFLINE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,205 @@
|
||||
package com.fastbee.data.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.core.mq.DeviceStatusBo;
|
||||
import com.fastbee.common.core.notify.AlertPushParams;
|
||||
import com.fastbee.common.enums.DeviceStatus;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.iot.domain.*;
|
||||
import com.fastbee.iot.model.AlertSceneSendVO;
|
||||
import com.fastbee.mqtt.manager.MqttRemoteManager;
|
||||
import com.fastbee.iot.service.*;
|
||||
import com.fastbee.mq.redischannel.producer.MessageProducer;
|
||||
import com.fastbee.notify.core.service.NotifySendService;
|
||||
import com.fastbee.sip.domain.SipDevice;
|
||||
import com.fastbee.sip.domain.SipDeviceChannel;
|
||||
import com.fastbee.sip.enums.DeviceChannelStatus;
|
||||
import com.fastbee.sip.mapper.SipDeviceChannelMapper;
|
||||
import com.fastbee.sip.mapper.SipDeviceMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author gsb
|
||||
* @date 2023/2/20 17:13
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceJob {
|
||||
|
||||
@Resource
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private SipDeviceMapper sipDeviceMapper;
|
||||
|
||||
@Autowired
|
||||
private SipDeviceChannelMapper sipDeviceChannelMapper;
|
||||
|
||||
@Autowired
|
||||
private IDeviceLogService deviceLogService;
|
||||
|
||||
@Autowired
|
||||
private IAlertService alertService;
|
||||
|
||||
@Autowired
|
||||
private NotifySendService notifySendService;
|
||||
|
||||
@Autowired
|
||||
private IAlertLogService alertLogService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceAlertUserService deviceAlertUserService;
|
||||
|
||||
@Autowired
|
||||
private ISceneScriptService sceneScriptService;
|
||||
|
||||
public void updateSipDeviceOnlineStatus(Integer timeout) {
|
||||
List<SipDevice> devs = sipDeviceMapper.selectOfflineSipDevice(timeout);
|
||||
devs.forEach(item -> {
|
||||
if (!Objects.equals(item.getDeviceSipId(), "")) {
|
||||
//更新iot设备状态
|
||||
Device dev = deviceService.selectDeviceBySerialNumber(item.getDeviceSipId());
|
||||
if (dev != null && dev.getStatus() == DeviceStatus.ONLINE.getType()) {
|
||||
log.warn("定时任务:=>设备:{} 已经下线,设备超过{}秒没上线!",item.getDeviceSipId(),timeout);
|
||||
dev.setStatus(DeviceStatus.OFFLINE.getType());
|
||||
deviceService.updateDeviceStatusAndLocation(dev,"");
|
||||
DeviceStatusBo bo = DeviceStatusBo.builder()
|
||||
.serialNumber(dev.getSerialNumber())
|
||||
.status(DeviceStatus.OFFLINE)
|
||||
.build();
|
||||
MessageProducer.sendStatusMsg(bo);
|
||||
}
|
||||
//更新通道状态
|
||||
List<SipDeviceChannel> channels = sipDeviceChannelMapper.selectSipDeviceChannelByDeviceSipId(item.getDeviceSipId());
|
||||
channels.forEach(citem -> {
|
||||
citem.setStatus(DeviceChannelStatus.offline.getValue());
|
||||
sipDeviceChannelMapper.updateSipDeviceChannel(citem);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查设备上报日志
|
||||
*
|
||||
* @param cycle 设备上报日志周期(分钟)
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public void checkDeviceReportData(String TriggerId, Integer cycle) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date now = new Date();
|
||||
calendar.setTime(now);
|
||||
calendar.add(Calendar.MINUTE, -cycle);
|
||||
deviceLogService.selectDeviceReportData(calendar.getTime(), now).forEach(item -> {
|
||||
if (!item.getUnReportList().isEmpty()) {
|
||||
item.getUnReportList().forEach(s -> {
|
||||
//产生告警 设备序列号 和 id无数据
|
||||
alertPush(TriggerId, item.getSerialNumber(), s);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void alertPush(String TriggerId, String serialNumber, String identity) {
|
||||
// 获取告警场景id
|
||||
SceneScript triggerScript = new SceneScript();
|
||||
SceneScript alertlog = new SceneScript();
|
||||
triggerScript.setId(TriggerId);
|
||||
List<SceneScript> list = sceneScriptService.selectSceneScriptList(triggerScript);
|
||||
if (!list.isEmpty()) {
|
||||
triggerScript = list.get(0);
|
||||
alertlog.setId(identity);
|
||||
alertlog.setValue("无数据上报");
|
||||
alertlog.setSceneId(triggerScript.getSceneId());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AlertLog> alertLogList = new ArrayList<>();
|
||||
// 查询设备信息
|
||||
Device device = deviceService.selectDeviceBySerialNumber(serialNumber);
|
||||
Optional.ofNullable(device).orElseThrow(() -> new ServiceException("告警推送,设备不存在" + "[{" + serialNumber + "}]"));
|
||||
// 获取场景相关的告警参数,告警必须要是启动状态
|
||||
List<AlertSceneSendVO> sceneSendVOList = alertService.listByAlertIds(alertlog.getSceneId());
|
||||
if (CollectionUtils.isEmpty(sceneSendVOList)) {
|
||||
return;
|
||||
}
|
||||
// 获取告警推送参数
|
||||
AlertPushParams alertPushParams = new AlertPushParams();
|
||||
alertPushParams.setDeviceName(device.getDeviceName());
|
||||
alertPushParams.setSerialNumber(serialNumber);
|
||||
// 多租户改版查询自己配置的告警用户
|
||||
DeviceAlertUser deviceAlertUser = new DeviceAlertUser();
|
||||
deviceAlertUser.setDeviceId(device.getDeviceId());
|
||||
List<DeviceAlertUser> deviceUserList = deviceAlertUserService.selectDeviceAlertUserList(deviceAlertUser);
|
||||
if (CollectionUtils.isNotEmpty(deviceUserList)) {
|
||||
alertPushParams.setUserPhoneSet(deviceUserList.stream().map(DeviceAlertUser::getPhoneNumber).filter(StringUtils::isNotEmpty).collect(Collectors.toSet()));
|
||||
alertPushParams.setUserIdSet(deviceUserList.stream().map(DeviceAlertUser::getUserId).collect(Collectors.toSet()));
|
||||
}
|
||||
String address;
|
||||
if (StringUtils.isNotEmpty(device.getNetworkAddress())) {
|
||||
address = device.getNetworkAddress();
|
||||
} else if (StringUtils.isNotEmpty(device.getNetworkIp())) {
|
||||
address = device.getNetworkIp();
|
||||
} else if (Objects.nonNull(device.getLongitude()) && Objects.nonNull(device.getLatitude())) {
|
||||
address = device.getLongitude() + "," + device.getLatitude();
|
||||
} else {
|
||||
address = "未知地点";
|
||||
}
|
||||
alertPushParams.setAddress(address);
|
||||
alertPushParams.setAlertTime(DateUtils.parseDateToStr(DateUtils.YY_MM_DD_HH_MM_SS, new Date()));
|
||||
// 获取告警关联模版id
|
||||
for (AlertSceneSendVO alertSceneSendVO : sceneSendVOList) {
|
||||
List<AlertNotifyTemplate> alertNotifyTemplateList = alertService.listAlertNotifyTemplate(alertSceneSendVO.getAlertId());
|
||||
alertPushParams.setAlertName(alertSceneSendVO.getAlertName());
|
||||
for (AlertNotifyTemplate alertNotifyTemplate : alertNotifyTemplateList) {
|
||||
alertPushParams.setNotifyTemplateId(alertNotifyTemplate.getNotifyTemplateId());
|
||||
notifySendService.alertSend(alertPushParams);
|
||||
}
|
||||
List<AlertLog> alist = alertLogService.selectAlertLogListByCreateBy(alertlog.getSceneId().toString(), alertlog.getId(), 2);
|
||||
if (alist.isEmpty()) {
|
||||
AlertLog alertLog = buildAlertLog(alertSceneSendVO, device, alertlog);
|
||||
alertLogList.add(alertLog);
|
||||
} else {
|
||||
//重复未处理告警,只更新告警发生时间
|
||||
for (AlertLog alertLog : alist) {
|
||||
alertLog.setCreateTime(new Date());
|
||||
alertLogService.updateAlertLog(alertLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 保存告警日志
|
||||
alertLogService.insertAlertLogBatch(alertLogList);
|
||||
}
|
||||
|
||||
private AlertLog buildAlertLog(AlertSceneSendVO alertSceneSendVO, Device device, SceneScript Item) {
|
||||
AlertLog alertLog = new AlertLog();
|
||||
alertLog.setAlertName(alertSceneSendVO.getAlertName());
|
||||
alertLog.setAlertLevel(alertSceneSendVO.getAlertLevel());
|
||||
alertLog.setSerialNumber(device.getSerialNumber());
|
||||
alertLog.setProductId(device.getProductId());
|
||||
alertLog.setDeviceName(device.getDeviceName());
|
||||
alertLog.setUserId(device.getTenantId());
|
||||
alertLog.setStatus(2);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", Item.getId());
|
||||
jsonObject.put("value", Item.getValue());
|
||||
jsonObject.put("remark", "");
|
||||
alertLog.setDetail(jsonObject.toJSONString());
|
||||
alertLog.setCreateBy(Item.getSceneId().toString());
|
||||
alertLog.setRemark(Item.getId());
|
||||
alertLog.setCreateTime(new Date());
|
||||
return alertLog;
|
||||
}
|
||||
}
|
@ -0,0 +1,376 @@
|
||||
package com.fastbee.data.service.impl;
|
||||
|
||||
import com.fastbee.common.constant.ScheduleConstants;
|
||||
import com.fastbee.common.exception.job.TaskException;
|
||||
import com.fastbee.iot.domain.DeviceJob;
|
||||
import com.fastbee.iot.mapper.DeviceJobMapper;
|
||||
import com.fastbee.iot.service.IDeviceJobService;
|
||||
import com.fastbee.iot.cache.IDeviceCache;
|
||||
import com.fastbee.data.quartz.CronUtils;
|
||||
import com.fastbee.data.quartz.ScheduleUtils;
|
||||
import com.fastbee.quartz.domain.SysJob;
|
||||
import com.fastbee.quartz.mapper.SysJobMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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
|
||||
@Slf4j
|
||||
public class DeviceJobServiceImpl implements IDeviceJobService
|
||||
{
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Autowired
|
||||
private DeviceJobMapper jobMapper;
|
||||
|
||||
@Autowired
|
||||
private SysJobMapper sysJobMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() throws SchedulerException, TaskException
|
||||
{
|
||||
scheduler.clear();
|
||||
// 设备定时任务
|
||||
List<DeviceJob> jobList = jobMapper.selectJobAll();
|
||||
for (DeviceJob deviceJob : jobList)
|
||||
{
|
||||
ScheduleUtils.createScheduleJob(scheduler, deviceJob);
|
||||
}
|
||||
|
||||
// 系统定时任务
|
||||
List<SysJob> sysJobList = sysJobMapper.selectJobAll();
|
||||
for (SysJob job : sysJobList)
|
||||
{
|
||||
com.fastbee.quartz.util.ScheduleUtils.createScheduleJob(scheduler, job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取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()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据告警Ids批量删除调度信息
|
||||
*
|
||||
* @param alertIds 需要删除数据的告警Ids
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobByAlertIds(Long[] alertIds) throws SchedulerException
|
||||
{
|
||||
// 查出所有job
|
||||
List<DeviceJob> deviceJobs=jobMapper.selectShortJobListByAlertIds(alertIds);
|
||||
// 批量删除job
|
||||
int rows=jobMapper.deleteJobByAlertIds(alertIds);
|
||||
// 批量删除调度器
|
||||
for(DeviceJob job:deviceJobs){
|
||||
scheduler.deleteJob(ScheduleUtils.getJobKey(job.getJobId(), job.getJobGroup()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据场景联动Ids批量删除调度信息
|
||||
*
|
||||
* @param sceneIds 需要删除数据的场景Ids
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobBySceneIds(Long[] sceneIds) throws SchedulerException
|
||||
{
|
||||
// 查出所有job
|
||||
List<DeviceJob> deviceJobs=jobMapper.selectShortJobListBySceneIds(sceneIds);
|
||||
// 批量删除job
|
||||
int rows=jobMapper.deleteJobBySceneIds(sceneIds);
|
||||
// 批量删除调度器
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceJob> listShortJobBySceneId(Long[] sceneIds) {
|
||||
return jobMapper.selectShortJobListBySceneIds(sceneIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobByJobTypeAndDatasourceIds(Long[] datasourceIds, int jobType) throws SchedulerException {
|
||||
// 查出所有job
|
||||
List<DeviceJob> deviceJobs = jobMapper.selectListByJobTypeAndDatasourceIds(datasourceIds, jobType);
|
||||
// 批量删除job
|
||||
int rows = jobMapper.deleteJobByJobTypeAndDatasourceIds(datasourceIds, jobType);
|
||||
// 批量删除调度器
|
||||
for(DeviceJob job:deviceJobs){
|
||||
scheduler.deleteJob(ScheduleUtils.getJobKey(job.getJobId(), job.getJobGroup()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceJob> selectListByJobTypeAndDatasourceIds(Long[] datasourceIds, int jobType) {
|
||||
return jobMapper.selectListByJobTypeAndDatasourceIds(datasourceIds, jobType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件批量删除定时任务
|
||||
* @param deviceId
|
||||
* @param jobType
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobByJobTypeAndDeviceId(Long deviceId, int jobType) throws SchedulerException {
|
||||
// 查出所有job
|
||||
DeviceJob deviceJob = new DeviceJob();
|
||||
deviceJob.setJobType(jobType);
|
||||
deviceJob.setDeviceId(deviceId);
|
||||
List<DeviceJob> deviceJobs = jobMapper.selectJobList(deviceJob);
|
||||
// 批量删除job
|
||||
jobMapper.deleteJobByJobTypeAndDeviceId(deviceId, jobType);
|
||||
// 批量删除调度器
|
||||
for(DeviceJob job:deviceJobs){
|
||||
scheduler.deleteJob(ScheduleUtils.getJobKey(job.getJobId(), job.getJobGroup()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
package com.fastbee.data.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.fastbee.common.constant.FastBeeConstant;
|
||||
import com.fastbee.common.core.device.DeviceAndProtocol;
|
||||
import com.fastbee.common.core.mq.DeviceReportBo;
|
||||
import com.fastbee.common.core.mq.MQSendMessageBo;
|
||||
import com.fastbee.common.core.mq.message.DeviceMessage;
|
||||
import com.fastbee.common.core.mq.message.FunctionCallBackBo;
|
||||
import com.fastbee.common.core.mq.message.ModbusPollMsg;
|
||||
import com.fastbee.common.core.protocol.modbus.ModbusCode;
|
||||
import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
|
||||
import com.fastbee.common.enums.DeviceStatus;
|
||||
import com.fastbee.common.enums.ServerType;
|
||||
import com.fastbee.common.enums.TopicType;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.common.utils.BitUtils;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.common.utils.gateway.CRC16Utils;
|
||||
import com.fastbee.common.utils.gateway.mq.TopicsUtils;
|
||||
import com.fastbee.common.utils.modbus.ModbusUtils;
|
||||
import com.fastbee.data.service.IDeviceMessageService;
|
||||
import com.fastbee.iot.cache.ITSLCache;
|
||||
import com.fastbee.iot.domain.ModbusConfig;
|
||||
import com.fastbee.iot.domain.ModbusJob;
|
||||
import com.fastbee.iot.enums.DeviceType;
|
||||
import com.fastbee.iot.model.DeviceStatusVO;
|
||||
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem;
|
||||
import com.fastbee.iot.model.VariableReadVO;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import com.fastbee.iot.service.IModbusJobService;
|
||||
import com.fastbee.iot.service.IProductService;
|
||||
import com.fastbee.iot.service.ISubGatewayService;
|
||||
import com.fastbee.iot.util.SnowflakeIdWorker;
|
||||
import com.fastbee.modbus.codec.ModbusEncoder;
|
||||
import com.fastbee.modbus.codec.ModbusProtocol;
|
||||
import com.fastbee.modbus.model.ModbusRtu;
|
||||
import com.fastbee.mq.redischannel.producer.MessageProducer;
|
||||
import com.fastbee.mqttclient.PubMqttClient;
|
||||
import com.fastbee.pakModbus.codec.ModbusRtuPakEncoder;
|
||||
import com.fastbee.pakModbus.codec.ModbusRtuPakProtocol;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceMessageServiceImpl implements IDeviceMessageService {
|
||||
|
||||
@Resource
|
||||
private PubMqttClient mqttClient;
|
||||
@Resource
|
||||
private ModbusEncoder modbusMessageEncoder;
|
||||
@Resource
|
||||
private IDeviceService deviceService;
|
||||
@Resource
|
||||
private TopicsUtils topicsUtils;
|
||||
@Resource
|
||||
private ITSLCache itslCache;
|
||||
@Resource
|
||||
private ModbusProtocol modbusProtocol;
|
||||
@Resource
|
||||
private IModbusJobService modbusJobService;
|
||||
|
||||
@Override
|
||||
public void messagePost(DeviceMessage deviceMessage) {
|
||||
String topicName = deviceMessage.getTopicName();
|
||||
String serialNumber = deviceMessage.getSerialNumber();
|
||||
DeviceAndProtocol deviceAndProtocol = deviceService.selectProtocolBySerialNumber(serialNumber);
|
||||
String transport = deviceAndProtocol.getTransport();
|
||||
TopicType type = TopicType.getType(topicName);
|
||||
topicName = topicsUtils.buildTopic(deviceAndProtocol.getProductId(), serialNumber,type);
|
||||
switch (type){
|
||||
case FUNCTION_GET:
|
||||
if (transport.equals(ServerType.MQTT.getCode())){
|
||||
mqttClient.publish(0, false, topicName, deviceMessage.getMessage().toString());
|
||||
}else if (transport.equals(ServerType.TCP.getCode())){
|
||||
//处理TCP下发
|
||||
}
|
||||
break;
|
||||
case PROPERTY_POST:
|
||||
//下发的不经过mqtt或TCP直接转发到数据处理模块
|
||||
DeviceReportBo reportBo = DeviceReportBo.builder()
|
||||
.serverType(ServerType.explain(transport))
|
||||
.data(BitUtils.hexStringToByteArray(deviceMessage.getMessage().toString()))
|
||||
.platformDate(DateUtils.getNowDate())
|
||||
.serialNumber(serialNumber)
|
||||
.topicName(topicName).build();
|
||||
MessageProducer.sendPublishMsg(reportBo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String messageEncode(ModbusRtu modbusRtu) {
|
||||
//兼容15、16功能码
|
||||
if (modbusRtu.getCode() == ModbusCode.Write10.getCode()){
|
||||
//计算:字节数=2*N;N为寄存器个数
|
||||
modbusRtu.setBitCount(2 * modbusRtu.getCount());
|
||||
}else if (modbusRtu.getCode() == ModbusCode.Write0F.getCode()){
|
||||
//计算:字节数=N/8 余数为0是 N需要再+1。N是线圈个数
|
||||
int i = modbusRtu.getCount() / 8;
|
||||
if (modbusRtu.getCount() % 8!= 0){
|
||||
i++;
|
||||
}
|
||||
modbusRtu.setBitCount(i);
|
||||
//计算线圈值,前端返回二进制的字符串,需要将高低位先翻转,在转化为16进制
|
||||
String reverse = StringUtils.reverse(modbusRtu.getBitString());
|
||||
modbusRtu.setBitData(BitUtils.string2bytes(reverse));
|
||||
}
|
||||
ByteBuf out = modbusMessageEncoder.encode(modbusRtu);
|
||||
byte[] result = new byte[out.writerIndex()];
|
||||
out.readBytes(result);
|
||||
ReferenceCountUtil.release(out);
|
||||
return ByteBufUtil.hexDump(CRC16Utils.AddCRC(result));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThingsModelSimpleItem> messageDecode(DeviceMessage deviceMessage) {
|
||||
// ProductCode productCode = productService.getProtocolBySerialNumber(deviceMessage.getSerialNumber());
|
||||
// ByteBuf buf = Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump(deviceMessage.getMessage()));
|
||||
// DeviceData deviceData = DeviceData.builder()
|
||||
// .buf(buf)
|
||||
// .productId(productCode.getProductId())
|
||||
// .serialNumber(productCode.getSerialNumber())
|
||||
// .data(ByteBufUtil.getBytes(buf))
|
||||
// .build();
|
||||
// return modbusRtuPakProtocol.decodeMessage(deviceData, deviceMessage.getSerialNumber());
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 变量读取
|
||||
* @param readVO
|
||||
*/
|
||||
@Override
|
||||
public void readVariableValue(VariableReadVO readVO){
|
||||
String serialNumber = readVO.getSerialNumber();
|
||||
assert !Objects.isNull(serialNumber) : "设备编号为空";
|
||||
DeviceAndProtocol deviceAndProtocol = deviceService.selectProtocolBySerialNumber(serialNumber);
|
||||
if (!deviceAndProtocol.getProtocolCode().equals(FastBeeConstant.PROTOCOL.ModbusRtu)) throw new ServiceException("非modbus协议请先配置主动采集协议");
|
||||
Long productId = deviceAndProtocol.getProductId();
|
||||
//如果是子设备,则获取网关子设备的产品id和设备编号
|
||||
Integer deviceType = deviceAndProtocol.getDeviceType();
|
||||
if (deviceType == DeviceType.SUB_GATEWAY.getCode()){
|
||||
serialNumber = deviceAndProtocol.getGwSerialNumber();
|
||||
productId = deviceAndProtocol.getGwProductId();
|
||||
}
|
||||
Integer type = readVO.getType();
|
||||
type = Objects.isNull(type) ? 1 : type;
|
||||
if (type == 1){
|
||||
//单个变量获取
|
||||
String identifier = readVO.getIdentifier();
|
||||
ThingsModelValueItem thingModels = itslCache.getSingleThingModels(deviceAndProtocol.getProductId(), identifier);
|
||||
ModbusConfig config = thingModels.getConfig();
|
||||
if (Objects.isNull(config)) throw new ServiceException("未配置modbus点位");
|
||||
thingModels.getConfig().setModbusCode(ModbusUtils.getReadModbusCode(config.getType(),config.getIsReadonly()));
|
||||
MQSendMessageBo messageBo = new MQSendMessageBo();
|
||||
messageBo.setThingsModel(JSON.toJSONString(thingModels));
|
||||
FunctionCallBackBo encode = modbusProtocol.encode(messageBo);
|
||||
List<String> commandList = new ArrayList<>();
|
||||
commandList.add(encode.getSources());
|
||||
ModbusPollMsg modbusPollMsg = new ModbusPollMsg();
|
||||
modbusPollMsg.setSerialNumber(serialNumber);
|
||||
modbusPollMsg.setProductId(productId);
|
||||
modbusPollMsg.setCommandList(commandList);
|
||||
DeviceStatusVO deviceStatusVO = deviceService.selectDeviceStatusAndTransportStatus(modbusPollMsg.getSerialNumber());
|
||||
modbusPollMsg.setTransport(deviceStatusVO.getTransport());
|
||||
if (deviceStatusVO.getStatus() != DeviceStatus.ONLINE.getType()){
|
||||
log.info("设备:[{}],不在线",modbusPollMsg.getSerialNumber());
|
||||
return;
|
||||
}
|
||||
MessageProducer.sendPropFetch(modbusPollMsg);
|
||||
// 测试将属性读取任务加入到队列
|
||||
// while (true){
|
||||
// try {
|
||||
// Thread.sleep(1010L);
|
||||
// MessageProducer.sendPropFetch(modbusPollMsg);
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}else {
|
||||
//读取当前设备的所有变量,这里读取所有的,判断传递的设备是网关设备、网关子设备、直连设备
|
||||
DeviceType code = DeviceType.transfer(deviceType);
|
||||
List<ModbusJob> modbusJobList = modbusJobService.selectDevicesJobByDeviceType(code, readVO.getSerialNumber());
|
||||
List<String> commandList = modbusJobList.stream().map(ModbusJob::getCommand).collect(Collectors.toList());
|
||||
ModbusPollMsg msg = new ModbusPollMsg();
|
||||
msg.setCommandList(commandList);
|
||||
msg.setTransport(deviceAndProtocol.getTransport());
|
||||
msg.setProductId(productId);
|
||||
msg.setSerialNumber(serialNumber);
|
||||
MessageProducer.sendPropFetch(msg);
|
||||
//测试使用
|
||||
// while (true){
|
||||
// try {
|
||||
// Thread.sleep(5000L);
|
||||
// MessageProducer.sendPropFetch(msg);
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.fastbee.data.service.impl;
|
||||
|
||||
import com.fastbee.common.constant.FastBeeConstant;
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeBo;
|
||||
import com.fastbee.common.core.mq.ota.OtaUpgradeDelayTask;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.data.service.IOtaUpgradeService;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.domain.Firmware;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
import com.fastbee.iot.service.IFirmwareService;
|
||||
import com.fastbee.iot.service.IProductService;
|
||||
import com.fastbee.mq.service.IMessagePublishService;
|
||||
import com.fastbee.mqtt.manager.MqttRemoteManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* OTA延迟升级实现
|
||||
*
|
||||
* @author bill
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OtaUpgradeServiceImpl implements IOtaUpgradeService {
|
||||
|
||||
@Autowired
|
||||
private IFirmwareService firmwareService;
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
@Resource
|
||||
private IMessagePublishService messagePublishService;
|
||||
|
||||
|
||||
@Override
|
||||
public void upgrade(OtaUpgradeDelayTask task) {
|
||||
//查询固件版本信息
|
||||
Firmware firmware = firmwareService.selectFirmwareByFirmwareId(task.getFirmwareId());
|
||||
Optional.ofNullable(firmware).orElseThrow(() -> new ServiceException("固件版本不存在!"));
|
||||
// 处理单个或多个设备的OTA升级,根据设备单个升级
|
||||
if (!CollectionUtils.isEmpty(task.getDevices())) {
|
||||
for (String serialNumber : task.getDevices()) {
|
||||
Device device = deviceService.selectDeviceBySerialNumber(serialNumber);
|
||||
handleSingle(task, firmware, serialNumber, device.getDeviceName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 根据产品查询设备整个产品升级处理
|
||||
handleProduct(task, firmware);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个设备升级
|
||||
*
|
||||
* @param task 升级bo
|
||||
* @param firmware 固件
|
||||
* @param serialNumber 设备编号
|
||||
*/
|
||||
private void handleSingle(OtaUpgradeDelayTask task, Firmware firmware, String serialNumber,String deviceName) {
|
||||
OtaUpgradeBo upgradeBo = OtaUpgradeBo.builder()
|
||||
.serialNumber(serialNumber)
|
||||
.taskId(task.getTaskId())
|
||||
.firmwareVersion(firmware.getVersion().toString())
|
||||
.otaId(firmware.getFirmwareId())
|
||||
.productId(firmware.getProductId())
|
||||
.otaUrl(firmware.getFilePath()) //文件升级URL
|
||||
.pushType(0) // 目前支持url升级,0表示url升级
|
||||
.seqNo(firmware.getSeqNo())
|
||||
.deviceName(deviceName)
|
||||
.firmwareName(firmware.getFirmwareName())
|
||||
.build();
|
||||
/* 校验设备是否在集群节点上*/
|
||||
if (MqttRemoteManager.checkDeviceStatus(serialNumber)) {
|
||||
// 客户端在本节点上,发布OTA升级,推送至MQ
|
||||
messagePublishService.publish(upgradeBo, FastBeeConstant.CHANNEL.UPGRADE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理整个产品的设备升级
|
||||
*
|
||||
* @param task 升级bo
|
||||
* @param firmware 固件
|
||||
*/
|
||||
private void handleProduct(OtaUpgradeDelayTask task, Firmware firmware) {
|
||||
//查询产品下的所有设备编码
|
||||
List<Device> deviceList = deviceService.selectDevicesByProductId(firmware.getProductId(),1);
|
||||
for (Device device : deviceList) {
|
||||
handleSingle(task, firmware, device.getSerialNumber(), device.getDeviceName());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user