若依微服务1.3.6

1、job修改
2、设备信息增加对时和拍照功能
3、增加publish下发指令到redis
4、场景用户名和密码自动生成,不能修改
5、监控单元获取监控单元类型过滤
6、计算设备在线情况完善
dev 1.3.6
xins 1 year ago
parent e420fff4b8
commit b636559aec

@ -2,6 +2,8 @@ package com.ruoyi.tdengine.api.domain;
import com.ruoyi.common.core.web.domain.BaseEntity;
import java.util.List;
/**
* @Description:
* @ClassName: DeviceStatus
@ -26,6 +28,8 @@ public class DeviceStatus extends BaseEntity {
private Long startTime;
private Long endTime;
private List<TdField> schemaFields;
public Long getTs() {
return ts;
}
@ -89,4 +93,12 @@ public class DeviceStatus extends BaseEntity {
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public List<TdField> getSchemaFields() {
return schemaFields;
}
public void setSchemaFields(List<TdField> schemaFields) {
this.schemaFields = schemaFields;
}
}

@ -33,7 +33,7 @@ public class HwDictConstants {
public static final String FUNCTION_MODE_SERVICE = "2";//设备模型功能模式服务
public static final String FUNCTION_MODE_EVENT = "3";//设备模型功能模式事件
public static final String RW_FLAG_RW = "1";//读写
public static final String RW_FLAG_RW = "1";//读写
public static final String RW_FLAG_READ = "2";//只读
public static final String DEVICE_STATUS_PUBLISH = "1";//设备状态:已发布
@ -83,9 +83,22 @@ public class HwDictConstants {
SCENE_MODE_ROUTER_MAP.put(SCENE_MODE_GPS, ROUTER_GPS);
}
public static final String DEVICE_ONLINE_STATUS_ONLINE="1";//在线状态
public static final String DEVICE_ONLINE_STATUS_OFFLINE="0"; //离线状态
public static final String DEVICE_ONLINE_STATUS_ONLINE = "1";//在线状态
public static final String DEVICE_ONLINE_STATUS_OFFLINE = "0"; //离线状态
public static final String ALARM_HANDLE_STATUS_YES = "1";//已处理
public static final String ALARM_HANDLE_STATUS_NO = "0";//未处理
public static final String SCENE_STATUS_NORMAL = "1";//正常状态
public static final String CONTROL_COMMAND_REDIS_KEY = "mqtt:channel:down";//下发控制指令到redis的key
public static final String CONTROL_COMMAND_TOPIC_VALUE = "/v1/{}/device/command";//下发控制指令的topic
public static final String CONTROL_COMMAND_TOPIC_KEY = "TOPIC";
public static final String CONTROL_COMMAND_PAYLOAD_KEY = "Payload";
public static final String CONTROL_COMMAND_PAYLOAD_MID_KEY = "mid";
public static final String CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY = "timestamp";
public static final String CONTROL_COMMAND_PAYLOAD_TYPE_KEY = "type";
public static final String CONTROL_COMMAND_PAYLOAD_PARAM_KEY = "param";
public static final String DEVICEMODE_GPS_FLAG_NO="0";
}

@ -130,8 +130,6 @@ public class DataScopeAspect {
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
}
System.out.println("---"+ sqlString.toString());
Object params = joinPoint.getArgs()[0];
if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
BaseEntity baseEntity = (BaseEntity) params;
@ -139,7 +137,6 @@ public class DataScopeAspect {
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
}
StringBuilder tenantFilterSql = getTenantFilterSql(user, tenantAlias);
System.out.println("------"+tenantFilterSql.toString());
if (StringUtils.isNotBlank(tenantFilterSql.toString())) {
baseEntity.getParams().put(TENANT_DATA_SCOPE, " AND (" + tenantFilterSql.substring(4) + ")");
}

@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.HwMonitorUnit;
import com.ruoyi.business.domain.HwScene;
import com.ruoyi.business.domain.VO.DeviceControlVo;
import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwMonitorUnitVo;
import com.ruoyi.business.service.IHwDeviceModeService;
@ -193,7 +194,19 @@ public class HwDeviceController extends BaseController
{
device.setUpdateBy(SecurityUtils.getUsername());
device.setUpdateTime(new Date());
return toAjax(hwDeviceService.updateHwDevice(device));
return toAjax(hwDeviceService.changeDeviceStatus(device));
}
/**
*
*/
@RequiresPermissions("business:device:edit")
@Log(title = "下发设备控制指令", businessType = BusinessType.UPDATE)
@PutMapping("/publishControlCommand")
public AjaxResult publishControlCommand(@RequestBody DeviceControlVo deviceControlVo)
{
hwDeviceService.publishControlCommand(deviceControlVo);
return success();
}
@GetMapping("/computeOnlineDevicecCount/{days}")

@ -5,7 +5,6 @@ import com.ruoyi.business.domain.*;
import com.ruoyi.business.domain.VO.*;
import com.ruoyi.business.service.*;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.TdEngineConstants;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
@ -16,10 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/monitorPlatform")

@ -136,22 +136,14 @@ public class HwMonitorUnitController extends BaseController
@RequiresPermissions("business:monitorUnit:list")
@GetMapping("/getMonitorUnitTypes")
public AjaxResult getMonitorUnitTypes(HwMonitorUnitType monitorUnitType)
@GetMapping(value = {"/getMonitorUnitTypes/", "/getMonitorUnitTypes/{sceneId}"})
public AjaxResult getMonitorUnitTypes(@PathVariable(value = "sceneId", required = false) Long sceneId)
{
HwMonitorUnitType monitorUnitType = new HwMonitorUnitType();
monitorUnitType.setSceneId(sceneId);
return success(monitorUnitTypeService.selectHwMonitorUnitTypeList(monitorUnitType));
}
@RequiresPermissions("business:monitorUnit:list")
@GetMapping("/getEditedMonitorUnitTypes")
public AjaxResult getEditedMonitorUnitTypes(HwMonitorUnitType monitorUnitType)
{
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = loginUser.getSysUser();
monitorUnitType.setTenantId(user.getTenantId());
return success(monitorUnitTypeService.selectHwMonitorUnitTypeList4Select(monitorUnitType));
}
/**
*
*/

@ -168,6 +168,8 @@ public class HwDevice extends BaseEntity {
private String deviceModeName;
private String tenantName;
private String gpsFlag;
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
@ -393,6 +395,14 @@ public class HwDevice extends BaseEntity {
this.tenantName = tenantName;
}
public String getGpsFlag() {
return gpsFlag;
}
public void setGpsFlag(String gpsFlag) {
this.gpsFlag = gpsFlag;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

@ -73,6 +73,14 @@ public interface IHwDeviceService
*/
public int updateHwDevice(HwDevice hwDevice);
/**
*
*
* @param hwDevice
* @return
*/
public int changeDeviceStatus(HwDevice hwDevice);
/**
*
*

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.HwScene;
import com.ruoyi.business.domain.VO.DeviceControlVo;
@ -12,6 +13,7 @@ import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.mapper.HwDeviceMapper;
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
import com.ruoyi.business.mapper.HwDeviceModeMapper;
import com.ruoyi.business.mapper.HwSceneMapper;
import com.ruoyi.business.service.IHwDeviceService;
import com.ruoyi.common.core.constant.Constants;
@ -46,6 +48,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
@Autowired
private HwDeviceMapper hwDeviceMapper;
@Autowired
private HwDeviceModeMapper hwDeviceModeMapper;
@Autowired
private HwSceneMapper hwSceneMapper;
@Autowired
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
@ -75,7 +79,13 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
@Override
public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId) {
return hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId);
HwDevice device = hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId);
Long deviceModeId = device.getDeviceModeId();
if (deviceModeId != null) {
HwDeviceMode mode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId);
device.setGpsFlag(mode != null ? mode.getGpsFlag() : HwDictConstants.DEVICEMODE_GPS_FLAG_NO);
}
return device;
}
/**
@ -317,6 +327,58 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
return rows;
}
/**
*
*
* @param hwDevice
* @return
*/
@Override
public int changeDeviceStatus(HwDevice hwDevice) {
HwDevice dbDevice = hwDeviceMapper.selectHwDeviceByDeviceId(hwDevice.getDeviceId());
if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) {
throw new ServiceException("已发布状态不能修改");
}
hwDevice.setUpdateTime(DateUtils.getNowDate());
return hwDeviceMapper.updateHwDevice(hwDevice);
}
/**
* @param: deviceControlVo
* @description
* @author xins
* @date 2023-09-25 14:56
*/
@Override
public void publishControlCommand(DeviceControlVo deviceControlVo) {
JSONObject controlCommandJson = new JSONObject();
StringBuilder controlCommandTopic = new StringBuilder();
Long deviceId = deviceControlVo.getDeviceId();
HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId);
String deviceType = device.getDeviceType();
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
Long gatewayDeviceId = device.getReleatedDeviceId();
HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId);
controlCommandTopic.append(StringUtils
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, gatewayDevice.getDeviceCode()));
} else {
controlCommandTopic.append(StringUtils
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, device.getDeviceCode()));
}
JSONObject payloadJson = new JSONObject();
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, device.getDeviceCode());
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位s
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, deviceControlVo.getType());
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, "{}");
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic.toString());
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString());
System.out.println("---" + controlCommandJson.toString());
redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString());
}
/**
* @param: hwDevice
* @param: dbDevice
@ -494,8 +556,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE);
hwDeviceVo.setDeviceDataMap(ddValueMap);
//TODO:去掉下边一行
ddValueMap.put("ii", "http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg");
acquisitionDeviceVos.add(hwDeviceVo);
});
@ -553,50 +613,76 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
}
private Map<Long, Integer> computeDeviceCountPerDay(Long startTime, Long endTime) {
//先增加需要查询的字段名称由于tdengine用last和last_row查询时字段显示有bug所以需要设置要查询的字段
List<TdField> schemaFields = new ArrayList<TdField>();
TdField deviceTypeField = new TdField();
deviceTypeField.setFieldName(TdEngineConstants.ST_TAG_DEVICETYPE);
TdField onlineStatusField = new TdField();
onlineStatusField.setFieldName(TdEngineConstants.ST_TAG_ONLINESTATUS);
schemaFields.add(deviceTypeField);
schemaFields.add(onlineStatusField);
DeviceStatus queryGroupStatus = new DeviceStatus();
queryGroupStatus.setStartTime(startTime);
queryGroupStatus.setEndTime(endTime);
queryGroupStatus.setSchemaFields(schemaFields);
DeviceStatus queryLastStatus = new DeviceStatus();
queryLastStatus.setEndTime(startTime);
queryLastStatus.setSchemaFields(schemaFields);
// System.out.println(DateUtils.dateTime(new Date(startTime)) + "----" + DateUtils.dateTime(new Date(endTime)));
Map<Long, Integer> onlineDeviceCountByDay = new HashMap<Long, Integer>();
//先获取starttime和endtime时间范围内在线的设备状态信息
Map<Long, List<DeviceStatus>> groupDeviceStatuMapList =
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData();
if (groupDeviceStatuMapList == null) {
groupDeviceStatuMapList = new HashMap<>();
}
//获取在endtime之前最后的设备状态信息有些设备会一直在线没有连续的上线下线记录所以要获取最近的设备状态信息来补齐后面的设备在线情况
List<Map<String, Object>> lastDeviceStatuMapList =
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData();
for (Map<String, Object> groupDeviceStatuMap : lastDeviceStatuMapList) {
DeviceStatus ds = new DeviceStatus();
for (Map.Entry<String, Object> entry : groupDeviceStatuMap.entrySet()) {
if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICEID)) {
ds.setDeviceId((long) (Integer) entry.getValue());
} else if (entry.getKey().equals(TdEngineConstants.ST_TAG_DEVICETYPE)) {
ds.setDeviceType((Integer) entry.getValue());
} else if (entry.getKey().equals(TdEngineConstants.ST_TAG_ONLINESTATUS)) {
ds.setOnlineStatus((Integer) entry.getValue());
if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) {
onlineDeviceCountByDay.put(startTime, 0);
} else {
for (Map<String, Object> groupDeviceStatuMap : lastDeviceStatuMapList) {
DeviceStatus ds = new DeviceStatus();
for (Map.Entry<String, Object> entry : groupDeviceStatuMap.entrySet()) {
switch (entry.getKey()) {
case TdEngineConstants.ST_TAG_DEVICEID:
ds.setDeviceId((long) (Integer) entry.getValue());
break;
case TdEngineConstants.ST_TAG_DEVICETYPE:
ds.setDeviceType((Integer) entry.getValue());
break;
case TdEngineConstants.ST_TAG_ONLINESTATUS:
ds.setOnlineStatus((Integer) entry.getValue());
break;
default:
break;
}
}
}
List<DeviceStatus> dss = groupDeviceStatuMapList.get(ds.getDeviceId());
int count = 0;
if (dss == null) {
if (String.valueOf(ds.getOnlineStatus())
.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) {
count = this.getDeviceCount(ds);
List<DeviceStatus> dss = groupDeviceStatuMapList.get(ds.getDeviceId());
int count = 0;
if (dss == null) {
if (String.valueOf(ds.getOnlineStatus())
.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) {
count = this.getDeviceCount(ds);
}
} else {
count = this.getDeviceCount(dss.get(0));
}
} else {
count = this.getDeviceCount(dss.get(0));
}
if (onlineDeviceCountByDay.get(startTime) == null) {
onlineDeviceCountByDay.put(startTime, count);
} else {
onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count);
if (onlineDeviceCountByDay.get(startTime) == null) {
onlineDeviceCountByDay.put(startTime, count);
} else {
onlineDeviceCountByDay.put(startTime, onlineDeviceCountByDay.get(startTime) + count);
}
}
}
@ -646,16 +732,4 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
}
/**
* @param: deviceControlVo
* @description
* @author xins
* @date 2023-09-25 14:56
*/
@Override
public void publishControlCommand(DeviceControlVo deviceControlVo) {
String channel = "";
String message = "";
redisTemplate.convertAndSend(channel, message);
}
}

@ -2,7 +2,10 @@ package com.ruoyi.business.service.impl;
import java.util.List;
import com.ruoyi.business.domain.HwMonitorUnit;
import com.ruoyi.business.domain.VO.HwMonitorUnitVo;
import com.ruoyi.business.mapper.HwMonitorUnitMapper;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.datascope.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,11 +21,13 @@ import com.ruoyi.business.service.IHwMonitorUnitTypeService;
* @date 2023-08-31
*/
@Service
public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
{
public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService {
@Autowired
private HwMonitorUnitTypeMapper hwMonitorUnitTypeMapper;
@Autowired
private HwMonitorUnitMapper hwMonitorUnitMapper;
/**
*
*
@ -30,8 +35,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
* @return
*/
@Override
public HwMonitorUnitType selectHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId)
{
public HwMonitorUnitType selectHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId) {
return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeByMonitorUnitTypeId(monitorUnitTypeId);
}
@ -43,8 +47,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
*/
@Override
@DataScope(tenantAlias = "hmut")
public List<HwMonitorUnitType> selectHwMonitorUnitTypeList(HwMonitorUnitType hwMonitorUnitType)
{
public List<HwMonitorUnitType> selectHwMonitorUnitTypeList(HwMonitorUnitType hwMonitorUnitType) {
return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeList(hwMonitorUnitType);
}
@ -56,8 +59,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
* @return
*/
@Override
public int insertHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType)
{
public int insertHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType) {
hwMonitorUnitType.setCreateTime(DateUtils.getNowDate());
return hwMonitorUnitTypeMapper.insertHwMonitorUnitType(hwMonitorUnitType);
}
@ -69,8 +71,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
* @return
*/
@Override
public int updateHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType)
{
public int updateHwMonitorUnitType(HwMonitorUnitType hwMonitorUnitType) {
hwMonitorUnitType.setUpdateTime(DateUtils.getNowDate());
return hwMonitorUnitTypeMapper.updateHwMonitorUnitType(hwMonitorUnitType);
}
@ -82,8 +83,15 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
* @return
*/
@Override
public int deleteHwMonitorUnitTypeByMonitorUnitTypeIds(Long[] monitorUnitTypeIds)
{
public int deleteHwMonitorUnitTypeByMonitorUnitTypeIds(Long[] monitorUnitTypeIds) {
for (Long monitorUnitTypeId : monitorUnitTypeIds) {
HwMonitorUnit queryMonitorUnit = new HwMonitorUnit();
queryMonitorUnit.setMonitorUnitTypeId(monitorUnitTypeId);
List<HwMonitorUnit> monitorUnits = hwMonitorUnitMapper.selectHwMonitorUnitList(queryMonitorUnit);
if (monitorUnits != null && monitorUnits.size() > 0) {
throw new ServiceException("所选择删除的监控单元类型已关联监控单元,不能删除");
}
}
return hwMonitorUnitTypeMapper.deleteHwMonitorUnitTypeByMonitorUnitTypeIds(monitorUnitTypeIds);
}
@ -94,8 +102,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
* @return
*/
@Override
public int deleteHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId)
{
public int deleteHwMonitorUnitTypeByMonitorUnitTypeId(Long monitorUnitTypeId) {
return hwMonitorUnitTypeMapper.deleteHwMonitorUnitTypeByMonitorUnitTypeId(monitorUnitTypeId);
}
@ -105,7 +112,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
* @param hwMonitorUnitType
* @return
*/
public List<HwMonitorUnitType> selectHwMonitorUnitTypeList4Select(HwMonitorUnitType hwMonitorUnitType){
public List<HwMonitorUnitType> selectHwMonitorUnitTypeList4Select(HwMonitorUnitType hwMonitorUnitType) {
return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeList(hwMonitorUnitType);
}
@ -117,8 +124,7 @@ public class HwMonitorUnitTypeServiceImpl implements IHwMonitorUnitTypeService
*/
@Override
@DataScope(tenantAlias = "hmut")
public List<HwMonitorUnitType> selectHwMonitorUnitTypeJoinList(HwMonitorUnitType hwMonitorUnitType)
{
public List<HwMonitorUnitType> selectHwMonitorUnitTypeJoinList(HwMonitorUnitType hwMonitorUnitType) {
return hwMonitorUnitTypeMapper.selectHwMonitorUnitTypeJoinList(hwMonitorUnitType);
}

@ -97,6 +97,7 @@ public class HwSceneServiceImpl implements IHwSceneService {
@Override
public List<HwSceneVo> selectHwSceneJoinList(HwSceneVo hwScene) {
hwScene.setSceneStatus(HwDictConstants.SCENE_STATUS_NORMAL);
return hwSceneMapper.selectHwSceneVoList(hwScene);
}
@ -112,7 +113,6 @@ public class HwSceneServiceImpl implements IHwSceneService {
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser sysUser = loginUser.getSysUser();
hwScene.setCreateBy(sysUser.getUserName());
hwScene.setTenantId(sysUser.getTenantId());
if (hwScene.getPreserveTime() == null) {
hwScene.setPreserveTime(new BigDecimal(90));
@ -120,13 +120,16 @@ public class HwSceneServiceImpl implements IHwSceneService {
if (hwScene.getTestPreserveTime() == null) {
hwScene.setTestPreserveTime(new BigDecimal(30));
}
// String randomKey = RandomStringUtils.random(12, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789");
// String randomSecret = RandomStringUtils.random(16, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789");
// hwScene.setModeKey(randomKey);
// hwScene.setModeSecret(randomSecret);
String randomAccount = RandomStringUtils.random(6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789");
String randomKey = RandomStringUtils.random(12, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789");
hwScene.setModeAccount(randomAccount);
hwScene.setModeKey(randomKey);
hwScene.setCreateTime(DateUtils.getNowDate());
int rows = hwSceneMapper.insertHwScene(hwScene);
this.updateDefaultFlag(hwScene);
this.createTdDatabase(hwScene);
return rows;
}
@ -148,20 +151,10 @@ public class HwSceneServiceImpl implements IHwSceneService {
@Override
@Transactional
public int updateHwScene(HwScene hwScene) {
if (hwScene.getDefaultFlag().equals(HwDictConstants.SCENE_DEFAULT_FLAG_YES)) {
HwScene queryScene = new HwScene();
queryScene.setTenantId(hwScene.getTenantId());
List<HwScene> dbScenes = hwSceneMapper.selectHwSceneList(queryScene);
if (dbScenes != null && dbScenes.isEmpty()) {
dbScenes.forEach(dbScene -> {
dbScene.setDefaultFlag(HwDictConstants.SCENE_DEFAULT_FLAG_NO);
hwSceneMapper.updateHwScene(dbScene);
});
}
}
this.updateDefaultFlag(hwScene);
hwScene.setUpdateTime(DateUtils.getNowDate());
int rows = hwSceneMapper.updateHwScene(hwScene);
int rows = hwSceneMapper.updateHwScene(hwScene);
this.updateRedisAuth(hwScene);
return rows;
}
@ -252,9 +245,9 @@ public class HwSceneServiceImpl implements IHwSceneService {
SysUser user = loginUser.getSysUser();
hwScene.setTenantId(user.getTenantId());
List<HwScene> scenes = hwSceneMapper.selectHwSceneList(hwScene);
scenes.forEach(s ->{
if(!s.getTenantId().equals( user.getTenantId())){
List<HwScene> scenes = hwSceneMapper.selectHwSceneList(hwScene);
scenes.forEach(s -> {
if (!s.getTenantId().equals(user.getTenantId())) {
s.setSelectedDisable("1");
}
});
@ -262,4 +255,27 @@ public class HwSceneServiceImpl implements IHwSceneService {
return scenes;
}
/**
* @param: hwScene
* @description
* @author xins
* @date 2023-09-26 18:19
*/
private void updateDefaultFlag(HwScene hwScene) {
if (hwScene.getDefaultFlag().equals(HwDictConstants.SCENE_DEFAULT_FLAG_YES)) {
HwScene queryScene = new HwScene();
queryScene.setTenantId(hwScene.getTenantId());
List<HwScene> dbScenes = hwSceneMapper.selectHwSceneList(queryScene);
if (dbScenes != null && !dbScenes.isEmpty()) {
dbScenes.forEach(dbScene -> {
if (hwScene.getSceneId()==null || (hwScene.getSceneId() != null &&
!hwScene.getSceneId().equals(dbScene.getSceneId()))) {
dbScene.setDefaultFlag(HwDictConstants.SCENE_DEFAULT_FLAG_NO);
hwSceneMapper.updateHwScene(dbScene);
}
});
}
}
}
}

@ -233,7 +233,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<sql id="selectHwDeviceJoinVo">
select hd.device_code,hd.device_name, hd.device_status,hd.online_status, hd.device_pic,hd.active_time,
select hd.device_code,hd.device_name, hd.device_status,hd.online_status, hd.device_pic,hd.active_time,hd.device_mode_id,
hmu.monitor_unit_name
from hw_device hd left join hw_monitor_unit hmu on hd.monitor_unit_id = hmu.monitor_unit_id </sql>

@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectHwSceneVo"/>
<where>
<if test="sceneName != null and sceneName != ''"> and scene_name like concat('%', #{sceneName}, '%')</if>
<if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
<if test="tenantId != null"> and tenant_id = #{tenantId}</if>
<if test="sceneModeId != null "> and scene_mode_id = #{sceneModeId}</if>
<if test="scenePic != null and scenePic != ''"> and scene_pic = #{scenePic}</if>
<if test="defaultFlag != null and defaultFlag != ''"> and default_flag = #{defaultFlag}</if>

@ -7,10 +7,7 @@ import com.ruoyi.tdengine.service.IDeviceStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -68,14 +65,18 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService {
params.put("superTableName", TdEngineConstants.DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME);
List<Map<String, Object>> deviceStatusMap = deviceStatusMapper.getLastOnlineDevices(queryDeviceStatus);
List<Map<String, Object>> filterMaps = new ArrayList<>();
String i18nKey = "";//todo国际化看在哪处理
for (Map<String, Object> latestMap : deviceStatusMap) {
Set<String> kk = latestMap.keySet();
for(String k : kk){
System.out.println(k+"==="+latestMap.get(k));
}
Map<String, Object> filterMap = latestMap.entrySet()
.stream()
.filter(entry -> entry.getValue() != null)
.collect(HashMap::new, (m, v) ->
m.put(i18nKey + v.getKey().substring(v.getKey().indexOf("(") + 1,
m.put(v.getKey().substring(v.getKey().indexOf("(") + 1,
v.getKey().indexOf(")")), v.getValue()), HashMap::putAll);
filterMaps.add(filterMap);
}

@ -15,7 +15,8 @@
<select id="getLastOnlineDevices" parameterType="com.ruoyi.tdengine.api.domain.DeviceStatus" resultType="java.util.Map" >
select last_row(*),last_row(deviceid) from #{params.databaseName}.#{params.superTableName}
select <foreach item="item" collection="schemaFields" separator=","
index="">last_row(${item.fieldName})</foreach>,last_row(deviceid) from #{params.databaseName}.#{params.superTableName}
<where>
<if test="endTime!= null and endTime != 0">
and ts &lt;= #{endTime}

@ -29,7 +29,7 @@ public class RyTask {
}
public void computeOnlineDevicecCount(int days) {
public void computeOnlineDevicesCount(Integer days) {
this.remoteBusinessService.computeOnlineDevicecCount(days);
}
}

@ -101,3 +101,15 @@ export function changeDeviceStatus(deviceId, deviceStatus) {
data: data
})
}
export function publishControlCommand(deviceId, type) {
const data = {
deviceId,
type
}
return request({
url: '/business/device/publishControlCommand',
method: 'put',
data: data
})
}

@ -1,4 +1,5 @@
import request from '@/utils/request'
import request from '@/utils/request';
import {parseStrEmpty} from "@/utils/ruoyi";
// 查询监控单元列表
export function listMonitorUnit(query) {
@ -63,20 +64,10 @@ export function getEditedScenes(query) {
}
// 查询监控单元类型供查询页面选择使用
export function getMonitorUnitTypes(query) {
export function getMonitorUnitTypes(sceneId) {
return request({
url: '/business/monitorUnit/getMonitorUnitTypes',
method: 'get',
params: query
})
}
// 查询监控单元类型供编辑页面选择使用
export function getEditedMonitorUnitTypes(query) {
return request({
url: '/business/monitorUnit/getEditedMonitorUnitTypes',
method: 'get',
params: query
url: '/business/monitorUnit/getMonitorUnitTypes/' + parseStrEmpty(sceneId),
method: 'get'
})
}

@ -166,6 +166,23 @@
</el-table-column-->
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-time"
@click="publishControlCommand(scope.row,'CMD_SYS_TIME_CHECK','设备对时')"
v-hasPermi="['business:device:edit']"
>设备对时
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-camera"
@click="publishControlCommand(scope.row,'CMD_SNAPSHOT','拍照')"
v-hasPermi="['business:device:edit']"
>拍照
</el-button>
<el-button
size="mini"
type="text"
@ -174,6 +191,10 @@
v-hasPermi="['business:device:edit']"
>修改
</el-button>
<el-button
size="mini"
type="text"
@ -353,7 +374,8 @@ import {
getMonitorTree,
getDeviceModes,
getGatewayDevices,
changeDeviceStatus
changeDeviceStatus,
publishControlCommand
} from "@/api/business/device";
import {getToken} from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
@ -888,6 +910,15 @@ export default {
row.deviceStatus = row.deviceStatus === "0" ? "1" : "0";
});
},
publishControlCommand(row,type,typeName){
this.$modal.confirm('确认要进行'+typeName+'么?').then(function () {
return publishControlCommand(row.deviceId, type);
}).then(() => {
this.$modal.msgSuccess("执行成功");
})
}
}
};
</script>

@ -308,8 +308,8 @@ export default {
functionIdentifier: [
{required: true, message: "请输入标识符", trigger: "blur"},
{
pattern: /^[a-z][a-z0-9_]+$/,
message: "2-20个字符小写字母、数字或下划线组成,开头必须为小写字母",
pattern: /^[a-zA-Z][a-z0-9_]+$/,
message: "2-20个字符小写字母、数字或下划线组成,开头必须为小写字母",
trigger: "blur"
}
],

@ -598,7 +598,7 @@ export default {
remark: null,
};
this.resetForm("modeFunctionForm");
//this.resetForm("modeFunctionForm");
},
handleUpdateAttribute(row) {
// this.reset();

@ -10,7 +10,7 @@
/>
</el-form-item>
<el-form-item label="所属场景" prop="sceneId">
<el-select v-model="queryParams.sceneId" placeholder="请选择">
<el-select v-model="queryParams.sceneId" placeholder="请选择" clearable @input="sceneChange">
<el-option
v-for="(scene, index) in scenes"
:key="index"
@ -20,7 +20,7 @@
</el-select>
</el-form-item>
<el-form-item label="监控单元类型" prop="monitorUnitTypeId">
<el-select v-model="queryParams.monitorUnitTypeId" placeholder="请选择">
<el-select v-model="queryParams.monitorUnitTypeId" placeholder="请选择" clearable>
<el-option
v-for="(monitorUnitType, index) in monitorUnitTypes"
:key="index"
@ -70,6 +70,7 @@
:default-expand-all="isExpandAll"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
<el-table-column label="监控单元编号" prop="monitorUnitId"/>
<el-table-column label="监控单元名称" prop="monitorUnitName"/>
<el-table-column label="所属场景" align="center" prop="sceneName"/>
<el-table-column label="监控单元类型" align="center" prop="monitorUnitTypeName"/>
@ -110,7 +111,7 @@
<el-input v-model="form.monitorUnitName" placeholder="请输入监控单元名称"/>
</el-form-item>
<el-form-item label="所属场景" prop="sceneId">
<el-select v-model="form.sceneId" placeholder="请选择" :disabled="sceneDisable">
<el-select v-model="form.sceneId" placeholder="请选择" :disabled="sceneDisable" @input="editedSceneChange">
<el-option
v-for="(scene, index) in editedScenes"
:key="index"
@ -202,7 +203,7 @@
<script>
import {
listMonitorUnit, getMonitorUnit, delMonitorUnit, addMonitorUnit, updateMonitorUnit
, getMonitorUnitTypes, getEditedMonitorUnitTypes, getScenes, getEditedScenes,getEditedMonitorUnits
, getMonitorUnitTypes, getScenes, getEditedScenes,getEditedMonitorUnits
} from "@/api/business/monitorUnit";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
@ -320,14 +321,24 @@ export default {
});
},
getMonitorUnitTypes() {
getMonitorUnitTypes().then(response => {
sceneChange(sceneId) {
this.queryParams.monitorUnitTypeId = null;
this.getMonitorUnitTypes(sceneId);
},
editedSceneChange(sceneId) {
this.form.monitorUnitTypeId = null;
this.getEditedMonitorUnitTypes(sceneId);
},
getMonitorUnitTypes(sceneId) {
getMonitorUnitTypes(sceneId).then(response => {
this.monitorUnitTypes = response.data;
});
},
getEditedMonitorUnitTypes() {
getEditedMonitorUnitTypes().then(response => {
getEditedMonitorUnitTypes(sceneId) {
getMonitorUnitTypes(sceneId).then(response => {
this.editedMonitorUnitTypes = response.data;
});
},
@ -386,6 +397,8 @@ export default {
monitorUnitField: null
};
this.resetForm("form");
this.editedScenes = [];
this.editedMonitorUnitTypes = [];
},
/** 搜索按钮操作 */
handleQuery() {
@ -400,7 +413,6 @@ export default {
handleAdd(row) {
this.sceneDisable= false;
this.getEditedScenes();
this.getEditedMonitorUnitTypes();
this.reset();
this.getTreeselect();
if (row != null && row.monitorUnitId) {
@ -423,7 +435,6 @@ export default {
handleUpdate(row) {
this.sceneDisable= true;
this.getEditedScenes();
this.getEditedMonitorUnitTypes();
this.reset();
this.getTreeselect();
if (row != null) {
@ -433,6 +444,8 @@ export default {
this.form = response.data;
this.open = true;
this.title = "修改监控单元";
this.getEditedMonitorUnitTypes(response.data.sceneId);
if (response.data.monitorPic != null) {
let previewFile = {};
previewFile.url = response.data.monitorPic

@ -76,6 +76,7 @@
<el-table v-loading="loading" :data="monitorUnitTypeList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="monitorUnitTypeId" />
<el-table-column label="类型名称" align="center" prop="monitorUnitTypeName" />
<el-table-column label="虚拟标识" align="center" prop="vitualFlag" >
<template slot-scope="scope">

@ -192,10 +192,10 @@
</el-select>
</el-form-item>
<el-form-item label="场景账号" prop="modeAccount">
<el-input v-model="form.modeAccount" placeholder="请输入场景账号"/>
<el-input v-model="form.modeAccount" placeholder="自动生成" disabled/>
</el-form-item>
<el-form-item label="场景密码" prop="modeKey">
<el-input v-model="form.modeKey" placeholder="请输入场景key"/>
<el-input v-model="form.modeKey" placeholder="自动生成" disabled/>
</el-form-item>
<el-form-item label="保存周期(天)" prop="preserveTime">
@ -346,18 +346,9 @@ export default {
authMode: [
{required: true, message: "认证方式不能为空", trigger: "blur"}
],
modeKey: [
{required: true, message: "场景key不能为空", trigger: "blur"}
],
modeSecret: [
{required: true, message: "场景secret不能为空", trigger: "blur"}
],
preserveTime: [
{required: true, message: "保存周期(单位默认90天不能为空", trigger: "blur"}
],
testPreserveTime: [
{required: true, message: "测试环境保存周期(单位默认30天不能为空", trigger: "blur"}
],
]
},
number: 0,

Loading…
Cancel
Save