若依微服务1.5.6

1、basic:innerauth
2、business:innerauth;计算在线设备数量需要是发布状态的设备;首页获取在运设备数量需判断是否传sceneId
3、dataprocess:数据处理针对base64图片没加前缀时的处理
4、job:innerauth
dev 1.5.6
xins 1 year ago
parent 8c4d7aba74
commit fc7dca2601

@ -2,10 +2,12 @@ package com.ruoyi.basic.api;
import com.ruoyi.basic.api.domain.HwTenant;
import com.ruoyi.basic.api.factory.RemoteBasicFallbackFactory;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.List;
@ -21,5 +23,5 @@ import java.util.List;
public interface RemoteBasicService {
@GetMapping("/tenant/getTenants")
R<List<HwTenant>> getTenants();
R<List<HwTenant>> getTenants(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -22,7 +22,7 @@ public class RemoteBasicFallbackFactory implements FallbackFactory<RemoteBasicSe
public RemoteBasicService create(Throwable throwable) {
return new RemoteBasicService() {
@Override
public R<List<HwTenant>> getTenants() {
public R<List<HwTenant>> getTenants(String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
};

@ -1,11 +1,13 @@
package com.ruoyi.business.api;
import com.ruoyi.business.api.factory.RemoteBusinessFallbackFactory;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
@FeignClient(contextId = "remoteBusinessService", value = ServiceNameConstants.BUSINESS_SERVICE, fallbackFactory = RemoteBusinessFallbackFactory.class)
public interface RemoteBusinessService {
@ -17,5 +19,5 @@ public interface RemoteBusinessService {
* @return
*/
@GetMapping("/device/computeOnlineDevicecCount/{days}")
public R<?> computeOnlineDevicecCount(@PathVariable("days") int days);
public R<?> computeOnlineDevicecCount(@PathVariable("days") int days, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -18,7 +18,7 @@ public class RemoteBusinessFallbackFactory implements FallbackFactory<RemoteBusi
public RemoteBusinessService create(Throwable throwable) {
return new RemoteBusinessService() {
@Override
public R<?> computeOnlineDevicecCount(int days) {
public R<?> computeOnlineDevicecCount(int days, String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
};

@ -19,10 +19,13 @@ public class TdEngineConstants {
public static final String PAYLOAD_PARAM = "param";//协议上传的param key
public static final String PAYLOAD_DATATYPE = "datatype";//协议上传数据数据类型的key
public static final String PAYLOAD_DATAVALUE = "datavalue";//协议上传数据的key
public static final String PAYLOAD_DEVICE_CODE = "uid";//协议上传设备编号的key
public static final String PAYLOAD_DEVICE_DATA_TYPE_IMAGE = "image";//协议上传图片类型的key
// public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀
public static final String DEFAULT_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀

@ -10,6 +10,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
@ -115,6 +116,7 @@ public class HwTenantController extends BaseController
/**
*
*/
@InnerAuth
@GetMapping("/getTenants")
public R<List<HwTenant>> getTenants(HwTenant hwTenant)
{

@ -13,6 +13,7 @@ import com.ruoyi.business.service.IHwDeviceModeService;
import com.ruoyi.business.service.IHwMonitorUnitService;
import com.ruoyi.business.service.IHwSceneService;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.api.domain.SysRole;
@ -191,10 +192,6 @@ public class HwDeviceController extends BaseController {
return success();
}
@GetMapping("/computeOnlineDevicecCount/{days}")
public void computeOnlineDevicecCount(@PathVariable("days") int days) {
hwDeviceService.computeOnlineDevicecCount(days);
}
@RequiresPermissions("business:device:rebuild")
@Log(title = "设备信息", businessType = BusinessType.REBUILD)
@ -203,4 +200,11 @@ public class HwDeviceController extends BaseController {
hwDeviceService.rebuildTdTables();
}
@InnerAuth
@GetMapping("/computeOnlineDevicecCount/{days}")
public void computeOnlineDevicecCount(@PathVariable("days") int days) {
hwDeviceService.computeOnlineDevicecCount(days);
}
}

@ -102,6 +102,7 @@ public class HwMonitorPlatformController extends BaseController {
@RequiresPermissions("business:monitor:index")
@GetMapping("/getDeviceOperations/{sceneId}")
public AjaxResult selectDeviceStatus(@PathVariable("sceneId") Long sceneId) {
System.out.println(("sceneid:" + sceneId));
return AjaxResult.success(hwDeviceService.getOnlineDevicesCount(sceneId));
}

@ -680,6 +680,15 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
});
}
public String getDeviceTslJson(Long deviceId) {
HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId);
String deviceCode = device.getDeviceCode();
String devideType = device.getDeviceType();
return "";
}
/**
* @param: hwDevice
* @param: dbDevice
@ -771,7 +780,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
List<Map<String, Object>> lastDeviceStatuMapList =
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus, SecurityConstants.INNER).getData();
if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) {
onlineDeviceCountByDay.put(startTime, 0);
onlineDeviceCountByDay.put(startTime, 0);//当天的在线设备数量为0
} else {
for (Map<String, Object> groupDeviceStatuMap : lastDeviceStatuMapList) {
DeviceStatus ds = new DeviceStatus();
@ -791,14 +800,14 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
}
}
List<DeviceStatus> dss = groupDeviceStatuMapList.get(ds.getDeviceId());
List<DeviceStatus> dss = groupDeviceStatuMapList.get(ds.getDeviceId());//获取此设备是否有状态信息
int count = 0;
if (dss == null) {
if (dss == null) {//如果没有获取则按照此设备最近的状态信息进行计算
if (String.valueOf(ds.getOnlineStatus())
.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) {
count = this.getDeviceCount(ds);
}
} else {
} else {//如果获取到就按最近的设备状态信息进行计算
count = this.getDeviceCount(dss.get(0));
}
@ -818,6 +827,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE)) {
HwDevice queryDevice = new HwDevice();
queryDevice.setReleatedDeviceId(ds.getDeviceId());
queryDevice.setDeviceStatus(HwDictConstants.DEVICE_STATUS_PUBLISH);
List<HwDevice> deviceList = hwDeviceMapper.selectHwDeviceList(queryDevice);
return deviceList == null ? 0 : deviceList.size();
} else {

@ -231,8 +231,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<select id="getOnlineDeviceNum" parameterType="Long">
SELECT count(1) as count FROM hw_device hd where hd.scene_id=#{sceneId} and hd.device_type=2 and hd.device_status=1
and exists (select 1 from hw_device hdd where hd.releated_device_id=hdd.device_id and hdd.online_status=1 and hdd.device_status=1)
SELECT count(1) as count FROM hw_device hd
where hd.device_type=2 and hd.device_status=1
and exists (select 1 from hw_device hdd where hd.releated_device_id=hdd.device_id and hdd.online_status=1 and hdd.device_status=1)
<if test="sceneId != null and sceneId!=0">and hd.scene_id=#{sceneId}</if>
</select>
<sql id="selectHwDeviceJoinVo">

@ -25,6 +25,23 @@ public class ImageUtils {
public static final String BASE64_PREFIX = "data:image/";//base64图片前缀
public static final String BASE64_SUFFIX = ";base64";//base64图片后缀
/**
* @param: base64Str
* @description
* @author xins
* @date 2023-10-16 13:31
* @return boolean
*/
public static boolean checkIsBase64(String base64Str){
try {
Base64.getDecoder().decode(base64Str);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
/**
* @param imagePatternArr
* @return String

@ -22,10 +22,10 @@ import com.ruoyi.dataprocess.mapper.HwDeviceMapper;
import com.ruoyi.dataprocess.mapper.HwElectronicFenceMapper;
import com.ruoyi.dataprocess.mapper.HwFenceAreaMapper;
import com.ruoyi.dataprocess.service.IDataProcessService;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.TdField;
import com.ruoyi.tdengine.api.domain.TdTableVo;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -92,6 +92,7 @@ public class DataProcessServiceImpl implements IDataProcessService {
for (int i = 0; i < paramArr.size(); i++) {
try {
JSONObject paramJson = paramArr.getJSONObject(i);
String dataType = paramJson.getString(TdEngineConstants.PAYLOAD_DATATYPE);
JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE);
deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase();
HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode);
@ -144,17 +145,12 @@ public class DataProcessServiceImpl implements IDataProcessService {
String extension = ImageUtils.getImageType(valueStr, imagePatternArr);
if (StringUtils.isNotBlank(extension)) {
//保存图片,并返回图片详细地址进行赋值保存
String imageFileName = null;
try {
imageFileName = ImageUtils.convertBase64ToImage(imagePath,
valueStr, "device" + deviceId, extension);
if (StringUtils.isNotBlank(imageFileName)) {
value = imageDomain + imagePrefix + imageFileName;
} else {
continue;
}
} catch (IOException e) {
logger.error("转换图片错误:" + e.getMessage(), e);
value = getImageFileName(imagePath, imageDomain, imagePrefix, valueStr, deviceId, extension);
if (value == null) continue;
} else if (dataType.equalsIgnoreCase(TdEngineConstants.PAYLOAD_DEVICE_DATA_TYPE_IMAGE)) {
if (ImageUtils.checkIsBase64(valueStr)) {//判断没有加前缀的情况
value = getImageFileName(imagePath, imageDomain, imagePrefix, valueStr, deviceId, "jpg");
if (value == null) continue;
}
}
@ -201,6 +197,19 @@ public class DataProcessServiceImpl implements IDataProcessService {
return paramArr.size();
}
private static String getImageFileName(String imagePath, String imageDomain, String imagePrefix, String valueStr, Long deviceId, String extension) {
try {
String imageFileName = ImageUtils.convertBase64ToImage(imagePath,
valueStr, "device" + deviceId, extension);
return imageDomain + imagePrefix + imageFileName;
} catch (IOException e) {
logger.error("转换图片错误:" + e.getMessage(), e);
}
return null;
}
/**
* @param: deviceId
* @param: monitorUnitId
@ -304,7 +313,9 @@ public class DataProcessServiceImpl implements IDataProcessService {
JSONObject json = JSON.parseObject(jsonData);
Object value = json.get("base64");
if (value instanceof String) {
String valueStr = (String) value;
System.out.println(Base64.isBase64(valueStr));
if (StringUtils.isNotBlank(valueStr)) {
/**
* ,

@ -182,7 +182,7 @@ public class FileUploadUtils {
String fileName = extractFilename(originalFileName, imagePath, extension);
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
// 去掉base64前缀 data:image/jpeg;base64,
// 去掉base64前缀 例如:data:image/jpeg;base64,
base64Str = base64Str.substring(base64Str.indexOf(",", 1) + 1);
// 解密解密的结果是一个byte数组
Base64.Decoder decoder = Base64.getDecoder();

@ -4,6 +4,7 @@ import java.util.List;
import com.ruoyi.basic.api.RemoteBasicService;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.apache.commons.lang3.ArrayUtils;
@ -150,7 +151,7 @@ public class SysDeptController extends BaseController {
public AjaxResult getTenants() {
Long tenantId = SecurityUtils.getTenantId();
if (tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)) {
return success(remoteBasicService.getTenants().getData());
return success(remoteBasicService.getTenants(SecurityConstants.INNER).getData());
} else {
return success();
}

@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
import com.ruoyi.basic.api.RemoteBasicService;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
@ -149,7 +150,7 @@ public class SysPostController extends BaseController
public AjaxResult getTenants() {
Long tenantId = SecurityUtils.getTenantId();
if (tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)) {
return success(remoteBasicService.getTenants().getData());
return success(remoteBasicService.getTenants(SecurityConstants.INNER).getData());
} else {
return success();
}

@ -2,6 +2,7 @@ package com.ruoyi.system.controller;
import com.ruoyi.basic.api.RemoteBasicService;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
@ -323,7 +324,7 @@ public class SysUserController extends BaseController {
public AjaxResult getTenants() {
Long tenantId = SecurityUtils.getTenantId();
if (tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)) {
return success(remoteBasicService.getTenants().getData());
return success(remoteBasicService.getTenants(SecurityConstants.INNER).getData());
} else {
return success();
}

@ -40,7 +40,7 @@ export function getAlarmInfos(query) {
export function getDeviceOperations(query) {
return request({
// baseURL:'/monitoring-api',
url: '/business/monitorPlatform/getDeviceOperations/1',
url: '/business/monitorPlatform/getDeviceOperations/0',
method: 'get',
})
}

@ -26,7 +26,7 @@
</p>
<p>
<span>状态</span>
<span style="color: #d9dee3">{{ MonitorInfo.monitorUnitStatus === 1 ? '正常' : '异常' }}</span>
<span style="color: #d9dee3">{{ MonitorInfo.monitorUnitStatus === '1' ? '正常' : '异常' }}</span>
</p>
<p>
<span>类型</span>

Loading…
Cancel
Save