Commit 1426a12d by huangjy

feat:设备属性读取和写入,第三方接口api

parent f40cf849
package com.makeit.api.controller.external; package com.makeit.api.external.controller;
import com.makeit.common.dto.BaseIdDTO; import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.page.PageReqDTO; import com.makeit.common.page.PageReqDTO;
......
package com.makeit.api.external.filter;
import org.apache.commons.io.IOUtils;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @Description: 解决request.getInputStream()只能读取一次的问题
* @PackageName: net.dlet.dhdemo.utils.dhutils
* @Name: MyRequestWrapper
* @Author: cure
* @CreateDate: 2020/09/06 4:44
* @ModifyUser:
* @ModifyDate:
* @ModifyDesc: 修改内容
* @DayNameFull: 星期日
* @ProjectName: dhdemo
* @Version: 1.0
**/
public class MyRequestWrapper extends HttpServletRequestWrapper {
private volatile byte[] body;
public MyRequestWrapper(HttpServletRequest request) throws IOException {
super(request);
body = IOUtils.toByteArray(super.getInputStream());
}
public byte[] getBody() {
return body;
}
public void setBody(byte[] body) {
this.body = body;
}
@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(getInputStream()));
}
@Override
public ServletInputStream getInputStream() throws IOException {
return new RequestBodyCachingInputStream(body);
}
private class RequestBodyCachingInputStream extends ServletInputStream {
private byte[] body;
private int lastIndexRetrieved = -1;
private ReadListener listener;
public RequestBodyCachingInputStream(byte[] body) {
this.body = body;
}
@Override
public int read() throws IOException {
if (isFinished()) {
return -1;
}
int i = body[lastIndexRetrieved + 1];
lastIndexRetrieved++;
if (isFinished() && listener != null) {
try {
listener.onAllDataRead();
} catch (IOException e) {
listener.onError(e);
throw e;
}
}
return i;
}
@Override
public boolean isFinished() {
return lastIndexRetrieved == body.length - 1;
}
@Override
public boolean isReady() {
return isFinished();
}
@Override
public void setReadListener(ReadListener listener) {
if (listener == null) {
throw new IllegalArgumentException("listener cann not be null");
}
if (this.listener != null) {
throw new IllegalArgumentException("listener has been set");
}
this.listener = listener;
if (!isFinished()) {
try {
listener.onAllDataRead();
} catch (IOException e) {
listener.onError(e);
}
} else {
try {
listener.onAllDataRead();
} catch (IOException e) {
listener.onError(e);
}
}
}
@Override
public int available() throws IOException {
return body.length - lastIndexRetrieved - 1;
}
@Override
public void close() throws IOException {
lastIndexRetrieved = body.length - 1;
body = null;
}
}
}
\ No newline at end of file
package com.makeit.api.external.filter;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @Description:
* @PackageName: net.dlet.dhdemo.configure
* @Name: RequestReplaceFilter
* @Author: cure
* @CreateDate: 2020/09/06 4:58
* @ModifyUser:
* @ModifyDate:
* @ModifyDesc: 修改内容
* @DayNameFull: 星期日
* @ProjectName: dhdemo
* @Version: 1.0
**/
@Component
public class RequestReplaceFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if (!(request instanceof MyRequestWrapper)) {
request = new MyRequestWrapper(request);
}
filterChain.doFilter(request, response);
}
}
\ No newline at end of file
package com.makeit.api.external.filter;
import com.makeit.api.external.util.RSAUtils;
import com.makeit.utils.old.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@WebFilter(urlPatterns = { "/iot/external/*"})
public class SignAuthFilter implements Filter {
private static Logger logger = LoggerFactory.getLogger(SignAuthFilter.class);
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
try {
String sign = request.getHeader("sign");
if (StringUtils.isEmpty(sign)) {
response.sendError(403, "Forbidden");
return;
}
logger.info("getted Authorization is ---> " + sign);
// 获取客户端ip
/* String ip = IpUtil.getIpAddr(request);
logger.info("getted ip is ---> " + ip);*/
MyRequestWrapper requestWrapper = new MyRequestWrapper(request);
String bodyString = new String(requestWrapper.getBody(), StandardCharsets.UTF_8);
logger.info("getted requestbody data is ---> " + bodyString);
String decryptJson = RSAUtils.privateDecrypt(sign, RSAUtils.getPrivateKey(RSAUtils.PRIVATE_KEY), "UTF-8");
boolean couldPass = decryptJson.equals(bodyString);
if (couldPass) {
// 放行
chain.doFilter(requestWrapper, response);
return;
}
response.sendError(403, "Forbidden");
} catch (Exception e) {
logger.error("验证失败: -> " + e.getMessage(), e);
response.sendError(403, "Forbidden");
}
}
@Override
public void destroy() {
}
}
package com.makeit.api.external.util;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
/**
* 1、公钥加密,则用私钥解密
* 2、私钥加密,则用公钥解密
* 3、公钥签名,私钥验签
*/
public class RSAUtils {
public static final String CHARSET = "UTF-8";
public static final String RSA_ALGORITHM = "RSA";
public static final String RSA_ALGORITHM_SIGN = "SHA256WithRSA";
public static final String PRIVATE_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDEjW_RLCPPCeAPWzQWIAwMGNvHf1pat27oH6CZDCG5nLwxyDsUgxdF89IB2_rLURVTkkrB5tq_dcBk5Wi2pmu2yMn8Dpk2XYsm0LJwJe3gg2qqRXQm8DGbf9kvtHUqBLe_24PMHL88YavJdrcS6HNlwwth2YINmViroqMZgqW4bQnmV4t5X4BO1dl3gTB5y8pRXd1zoKsLNgjzbuVBgieA0-e99eMsdjJadZFPzETQW-BO9Q6Kbbx4fIjOkqxiS8KzsiDSvf3KXG9lfvoz67vuNez_QBFauA_MJsUP_bgHLXFV9-XzcjCE2fkDbKbNHPAP20o1IM1S3G43mGzRwAb5AgMBAAECggEAV_nOsNuG86bB6V2zRKv3eHqv9O2l7bDpLXDqm1Z4yfHDsqyi9R1wD1mBCGAEM3kJiKyUVZIVG1mDUiX05rw6vkfFUNLf9RuNq0QCenwfqzxnQ-tuf_dG3Qkul1G4l6Qg8vk4VuYPGuHE2JoQe6Ab9tKEh7mpopievcRAKKz3rEIn4NGGfg4tlTP2hoZ_EhCDMc02UTtjm2YXUux2T2KLZPXMeClbxU1vTMTxFNp9edWyB9syLbfJp34lrnrueKnqpBPUI4oldKj-3QsE4v3Ie8wLTp5leiowzKqZUXqTplWAvROpIvVfj9eeouBPAz_IQR_U77c3m22cisCh-5QT-QKBgQD764Um0miLVQQIrfM9GQiWpiiM75nzmt4QaRkjoNg896b-qjDelG9K_EQ3RjopFuQBKBf7xY304qtD6nY_5IFRlhdB58nrSgPgSxLaShAQ2yUkdDPr00rDBu_9cAT9GZxSRmDhds-87rnz21QMNIofg2cpKNpl1HQQfTcFN9OETwKBgQDHvFvQ0bizfkh4o71pfD0tiiWEeQzV7KMjuwQ3nnUBfgv2Rd1QkOUo3x_dLBTRzacIslQ3DFljXqoBJWJasRFUSAyikR1KUAven7z5D3u-rdye6MLofKkf0YY_qAlNQXEDh9hzhlWqifd4UJTcZujVQNvkuvjldGnMMTK1W49GNwKBgBUbZ52YFYBPEDZ19KJS3aBZrZ4ZWSnK-P4hACU3DccV7Nz7f3q2rxh2SHTlImxc6Z-bL1897yXsc_MNyviRebBPRgWUmRtoqSh6wcqeV_hBlDwYrFz-6A2tICB46UIXijxufyGE5eTrj5L59nHLWSNIzDTroljT0yGqjBiY09ULAoGAN339hGbACh5rxBi55zS9Som3Irb--fBk4uhyo4FCwMdkS2fdtSSMhm53S9uTbTbV0XS6MREdRJ5oXSklykyno-Lgn8nxeVQD-DYpKolCuBdV1FCW1kDMPCraQZVOAEjOPUzgtjf8VQU_3A2HTjTJO3ZpoYLQ4-8T9cc1b22gwMECgYBCq2CPsNMSf55_VCD23b2B_PuppnowWw-k_zl4MkZGLtLJx5qsLRp-hNRvqW2t81fFkOieDdGg_6s7DPinwKfjH8KNgv7ke3kv9euiJ-AmF8HQKlRNCsX_-J7JeB39BHZXU9WPRI4YT8dR6NzZS3D_ug_Coeiq9TIFa2Za6Q6mXg";
public static final String PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxI1v0SwjzwngD1s0FiAMDBjbx39aWrdu6B-gmQwhuZy8Mcg7FIMXRfPSAdv6y1EVU5JKwebav3XAZOVotqZrtsjJ_A6ZNl2LJtCycCXt4INqqkV0JvAxm3_ZL7R1KgS3v9uDzBy_PGGryXa3EuhzZcMLYdmCDZlYq6KjGYKluG0J5leLeV-ATtXZd4EwecvKUV3dc6CrCzYI827lQYIngNPnvfXjLHYyWnWRT8xE0FvgTvUOim28eHyIzpKsYkvCs7Ig0r39ylxvZX76M-u77jXs_0ARWrgPzCbFD_24By1xVffl83IwhNn5A2ymzRzwD9tKNSDNUtxuN5hs0cAG-QIDAQAB";
public static void main(String[] args) throws Exception {
Map<String, String> keys = createKeys(2048);
System.out.println(keys);
RSAPublicKey publicKey = getPublicKey(keys.get("publicKey"));
RSAPrivateKey privateKey = getPrivateKey(keys.get("privateKey"));
String encrypt = publicEncrypt("{\"page\":1,\"limit\":10,\"data\":{}}", publicKey, "UTF-8");
System.out.println(encrypt);
String decrypt = privateDecrypt(encrypt, privateKey, "UTF-8");
System.out.println(decrypt);
}
/**
* 初始化RSA算法密钥对
*
* @param keySize RSA1024已经不安全了,建议2048
* @return 经过Base64编码后的公私钥Map, 键名分别为publicKey和privateKey
*/
private static Map<String, String> createKeys(int keySize) {
//为RSA算法创建一个KeyPairGenerator对象
KeyPairGenerator kpg;
try {
kpg = KeyPairGenerator.getInstance(RSA_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("No such algorithm-->[" + RSA_ALGORITHM + "]");
}
//初始化KeyPairGenerator对象,密钥长度
kpg.initialize(keySize);
//生成密匙对
KeyPair keyPair = kpg.generateKeyPair();
//得到公钥
Key publicKey = keyPair.getPublic();
String publicKeyStr = Base64.encodeBase64URLSafeString(publicKey.getEncoded());
//得到私钥
Key privateKey = keyPair.getPrivate();
String privateKeyStr = Base64.encodeBase64URLSafeString(privateKey.getEncoded());
Map<String, String> keyPairMap = new HashMap<String, String>();
keyPairMap.put("publicKey", publicKeyStr);
keyPairMap.put("privateKey", privateKeyStr);
return keyPairMap;
}
/**
* 得到公钥
* @param publicKey 密钥字符串(经过base64编码)
* @throws Exception
*/
public static RSAPublicKey getPublicKey(String publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
//通过X509编码的Key指令获得公钥对象
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(Base64.decodeBase64(publicKey));
RSAPublicKey key = (RSAPublicKey) keyFactory.generatePublic(x509KeySpec);
return key;
}
/**
* 得到私钥
* @param privateKey 密钥字符串(经过base64编码)
* @throws Exception
*/
public static RSAPrivateKey getPrivateKey(String privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
//通过PKCS#8编码的Key指令获得私钥对象
KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey));
RSAPrivateKey key = (RSAPrivateKey) keyFactory.generatePrivate(pkcs8KeySpec);
return key;
}
/**
* 公钥加密
* @param data
* @param publicKey
* @return
*/
public static String publicEncrypt(String data, RSAPublicKey publicKey, String encoding) {
if (StringUtils.isEmpty(encoding)) {
encoding = CHARSET;
}
try {
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return Base64.encodeBase64URLSafeString(rsaSplitCodec(cipher, Cipher.ENCRYPT_MODE, data.getBytes(encoding), publicKey.getModulus().bitLength()));
} catch (Exception e) {
throw new RuntimeException("加密字符串[" + data + "]时遇到异常", e);
}
}
/**
* 私钥解密
* @param data
* @param privateKey
* @return
*/
public static String privateDecrypt(String data, RSAPrivateKey privateKey, String encoding) {
if (StringUtils.isEmpty(encoding)) {
encoding = CHARSET;
}
try {
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, privateKey);
return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(data), privateKey.getModulus().bitLength()), encoding);
} catch (Exception e) {
throw new RuntimeException("解密字符串[" + data + "]时遇到异常", e);
}
}
/**
* 私钥加密
* @param data
* @param privateKey
* @return
*/
public static String privateEncrypt(String data, RSAPrivateKey privateKey, String encoding) {
if (StringUtils.isEmpty(encoding)) {
encoding = CHARSET;
}
try {
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
return Base64.encodeBase64URLSafeString(rsaSplitCodec(cipher, Cipher.ENCRYPT_MODE, data.getBytes(encoding), privateKey.getModulus().bitLength()));
} catch (Exception e) {
throw new RuntimeException("加密字符串[" + data + "]时遇到异常", e);
}
}
/**
* 公钥解密
* @param data
* @param publicKey
* @return
*/
public static String publicDecrypt(String data, RSAPublicKey publicKey, String encoding) {
if (StringUtils.isEmpty(encoding)) {
encoding = CHARSET;
}
try {
Cipher cipher = Cipher.getInstance(RSA_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, publicKey);
return new String(rsaSplitCodec(cipher, Cipher.DECRYPT_MODE, Base64.decodeBase64(data), publicKey.getModulus().bitLength()), encoding);
} catch (Exception e) {
throw new RuntimeException("解密字符串[" + data + "]时遇到异常", e);
}
}
/**
* 私钥签名
* @param data 需要签名的数据
* @param privateKey 私钥
* @return
*/
public static String sign(String data, RSAPrivateKey privateKey, String encoding) {
if (StringUtils.isEmpty(encoding)) {
encoding = CHARSET;
}
try {
//sign
Signature signature = Signature.getInstance(RSA_ALGORITHM_SIGN);
signature.initSign(privateKey);
signature.update(data.getBytes(encoding));
return Base64.encodeBase64URLSafeString(signature.sign());
} catch (Exception e) {
throw new RuntimeException("签名字符串[" + data + "]时遇到异常", e);
}
}
/**
* 公钥验签
* @param data 需要验签的原始数据
* @param sign 签名
* @param publicKey 公钥
* @return
*/
public static boolean verify(String data, String sign, RSAPublicKey publicKey, String encoding) {
if (StringUtils.isEmpty(encoding)) {
encoding = CHARSET;
}
try {
Signature signature = Signature.getInstance(RSA_ALGORITHM_SIGN);
signature.initVerify(publicKey);
signature.update(data.getBytes(encoding));
return signature.verify(Base64.decodeBase64(sign));
} catch (Exception e) {
throw new RuntimeException("验签字符串[" + data + "]时遇到异常", e);
}
}
private static byte[] rsaSplitCodec(Cipher cipher, int opmode, byte[] datas, int keySize) {
int maxBlock = 0;
if (opmode == Cipher.DECRYPT_MODE) {
maxBlock = keySize / 8;
} else {
maxBlock = keySize / 8 - 11;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] buff;
int i = 0;
try {
while (datas.length > offSet) {
if (datas.length - offSet > maxBlock) {
buff = cipher.doFinal(datas, offSet, maxBlock);
} else {
buff = cipher.doFinal(datas, offSet, datas.length - offSet);
}
out.write(buff, 0, buff.length);
i++;
offSet = i * maxBlock;
}
} catch (Exception e) {
throw new RuntimeException("加解密阀值为[" + maxBlock + "]的数据时发生异常", e);
}
byte[] resultDatas = out.toByteArray();
IOUtils.closeQuietly(out);
return resultDatas;
}
}
\ No newline at end of file
...@@ -18,6 +18,8 @@ public enum GlobalCodeMessageEnum { ...@@ -18,6 +18,8 @@ public enum GlobalCodeMessageEnum {
SYSTEM_ERROR_EXCEPTION(500, "system.error.exception"), SYSTEM_ERROR_EXCEPTION(500, "system.error.exception"),
// 请求方法不对 // 请求方法不对
SYSTEM_ERROR_NOT_ALLOWED(405, "system.error.method.not.allowed"), SYSTEM_ERROR_NOT_ALLOWED(405, "system.error.method.not.allowed"),
SYSTEM_ERROR_FORBIDDEN(403, "system.error.forbidden"),
// 未找到 // 未找到
SYSTEM_ERROR_NOT_FOUND(404, "system.error.not.found"), SYSTEM_ERROR_NOT_FOUND(404, "system.error.not.found"),
......
...@@ -35,6 +35,11 @@ public class ExceptionController implements ErrorController { ...@@ -35,6 +35,11 @@ public class ExceptionController implements ErrorController {
return ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_ERROR_NOT_ALLOWED.getCode(), return ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_ERROR_NOT_ALLOWED.getCode(),
GlobalCodeMessageEnum.SYSTEM_ERROR_NOT_ALLOWED.getMessage()); GlobalCodeMessageEnum.SYSTEM_ERROR_NOT_ALLOWED.getMessage());
} }
// 403
if (GlobalCodeMessageEnum.SYSTEM_ERROR_FORBIDDEN.getCode() == statusCode) {
return ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_ERROR_FORBIDDEN.getCode(),
GlobalCodeMessageEnum.SYSTEM_ERROR_FORBIDDEN.getMessage());
}
return ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_ERROR_EXCEPTION.getCode(), return ApiResponseUtils.fail(GlobalCodeMessageEnum.SYSTEM_ERROR_EXCEPTION.getCode(),
GlobalCodeMessageEnum.SYSTEM_ERROR_EXCEPTION.getMessage()); GlobalCodeMessageEnum.SYSTEM_ERROR_EXCEPTION.getMessage());
......
package com.makeit.module.iot.service; package com.makeit.module.iot.service;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.makeit.module.iot.util.HttpRequest; import com.makeit.module.iot.util.HttpRequest;
import com.makeit.module.iot.util.SimpleHttpRequest;
import com.makeit.module.iot.vo.DeviceInstanceEntity; import com.makeit.module.iot.vo.DeviceInstanceEntity;
import com.makeit.module.iot.vo.DeviceProperties;
import com.makeit.module.iot.vo.ResponseMessage; import com.makeit.module.iot.vo.ResponseMessage;
import com.makeit.utils.data.convert.JsonUtil; import com.makeit.utils.data.convert.JsonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -11,6 +14,7 @@ import org.springframework.scheduling.annotation.Async; ...@@ -11,6 +14,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -23,6 +27,23 @@ public class IotDevicePropertiesOperateService extends IotCommonService { ...@@ -23,6 +27,23 @@ public class IotDevicePropertiesOperateService extends IotCommonService {
public static final String DEVICE_PREFIX_URL = "/device-instance/"; public static final String DEVICE_PREFIX_URL = "/device-instance/";
public DeviceProperties deviceRead(String deviceId, String propertiesName) {
String url = iotUrl + "device/standard/" + deviceId + "/property/" + propertiesName;
HttpRequest request = new SimpleHttpRequest(url, httpClient);
request.headers(headerUtils.createHeadersOfParams(new HashMap<>()));
try {
ResponseMessage responseMessage = sendGet(url, request);
if (responseMessage.getStatus() == 200) {
return JSON.parseObject(responseMessage.getResult().toString(), DeviceProperties.class);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
/** /**
* 把设备写入属性 * 把设备写入属性
*/ */
......
package com.makeit.module.iot.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class DeviceProperties {
private Long createTime;
private String formatValue;
private Integer numberValue;
@ApiModelProperty("属性名称")
private String propertyName;
private Long timestamp;
private String type;
@ApiModelProperty("属性值")
private Integer value;
}
...@@ -10,6 +10,8 @@ import com.makeit.dto.platform.device.PlatDeviceQueryDTO; ...@@ -10,6 +10,8 @@ import com.makeit.dto.platform.device.PlatDeviceQueryDTO;
import com.makeit.dto.wechat.device.PlatDeviceAttrWechatDTO; import com.makeit.dto.wechat.device.PlatDeviceAttrWechatDTO;
import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO; import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO;
import com.makeit.dto.wechat.device.PlatDeviceSetupDTO; import com.makeit.dto.wechat.device.PlatDeviceSetupDTO;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.module.iot.vo.DeviceProperties;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.vo.platform.device.PlatDeviceListVO; import com.makeit.vo.platform.device.PlatDeviceListVO;
import com.makeit.vo.platform.device.PlatDeviceViewVO; import com.makeit.vo.platform.device.PlatDeviceViewVO;
...@@ -22,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -22,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* <p> * <p>
* 设备 前端控制器 * 设备 前端控制器
...@@ -65,6 +69,12 @@ public class PlatDeviceWechatController { ...@@ -65,6 +69,12 @@ public class PlatDeviceWechatController {
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
@ApiOperation("读取设备属性")
@PostMapping("readDeviceProperties")
public ApiResponseEntity<List<DeviceProperties>> readDeviceProperties(@RequestBody PlatDeviceAttrWechatDTO dto) {
return ApiResponseUtils.success(platDeviceService.readDeviceProperties(dto));
}
@ApiOperation("编辑设备属性") @ApiOperation("编辑设备属性")
@PostMapping("editDeviceProperties") @PostMapping("editDeviceProperties")
public ApiResponseEntity<?> editDeviceProperties(@RequestBody PlatDeviceAttrWechatDTO dto) { public ApiResponseEntity<?> editDeviceProperties(@RequestBody PlatDeviceAttrWechatDTO dto) {
......
...@@ -13,7 +13,7 @@ import lombok.Data; ...@@ -13,7 +13,7 @@ import lombok.Data;
* @since 2023-09-05 * @since 2023-09-05
*/ */
@Data @Data
@ApiModel(value = "PlatDeviceAttrWechatDTO对象", description = "设备属性") @ApiModel(value = "PlatDeviceAttrWechatDTO对象", description = "设备属性 跌倒:安装方式 安装高度 空间人体:安装方式 功能模式")
public class PlatDeviceAttrWechatDTO { public class PlatDeviceAttrWechatDTO {
@ApiModelProperty(value = "设备id") @ApiModelProperty(value = "设备id")
...@@ -30,5 +30,6 @@ public class PlatDeviceAttrWechatDTO { ...@@ -30,5 +30,6 @@ public class PlatDeviceAttrWechatDTO {
"进\":1,\"单位\":\"cm\"") "进\":1,\"单位\":\"cm\"")
private Integer radarHight; private Integer radarHight;
private String readProperties;
} }
...@@ -11,9 +11,12 @@ import com.makeit.dto.wechat.device.PlatDeviceAttrWechatDTO; ...@@ -11,9 +11,12 @@ import com.makeit.dto.wechat.device.PlatDeviceAttrWechatDTO;
import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO; import com.makeit.dto.wechat.device.PlatDeviceEditWechatDTO;
import com.makeit.dto.wechat.device.PlatDeviceSetupDTO; import com.makeit.dto.wechat.device.PlatDeviceSetupDTO;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.module.iot.vo.DeviceProperties;
import com.makeit.vo.platform.device.PlatDeviceListVO; import com.makeit.vo.platform.device.PlatDeviceListVO;
import com.makeit.vo.platform.device.PlatDeviceViewVO; import com.makeit.vo.platform.device.PlatDeviceViewVO;
import java.util.List;
/** /**
* <p> * <p>
* 设备 服务类 * 设备 服务类
...@@ -55,4 +58,6 @@ public interface PlatDeviceService extends IService<PlatDevice> { ...@@ -55,4 +58,6 @@ public interface PlatDeviceService extends IService<PlatDevice> {
void saasEdit(PlatDeviceEditSaasDTO dto); void saasEdit(PlatDeviceEditSaasDTO dto);
void editDeviceProperties(PlatDeviceAttrWechatDTO dto); void editDeviceProperties(PlatDeviceAttrWechatDTO dto);
List<DeviceProperties> readDeviceProperties(PlatDeviceAttrWechatDTO dto);
} }
...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.makeit.common.dto.BaseTenantDTO; import com.makeit.common.dto.BaseTenantDTO;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity; import com.makeit.common.entity.BaseEntity;
...@@ -25,6 +26,7 @@ import com.makeit.enums.CodeMessageEnum; ...@@ -25,6 +26,7 @@ import com.makeit.enums.CodeMessageEnum;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.device.PlatDeviceMapper; import com.makeit.mapper.platform.device.PlatDeviceMapper;
import com.makeit.module.iot.service.IotDevicePropertiesOperateService; import com.makeit.module.iot.service.IotDevicePropertiesOperateService;
import com.makeit.module.iot.vo.DeviceProperties;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.device.PlatDeviceOtherService; import com.makeit.service.platform.device.PlatDeviceOtherService;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
...@@ -284,4 +286,20 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -284,4 +286,20 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
devicePropertiesOperateService.deviceWrite(dto.getDeviceId(),dto.getRadarMount(),dto.getRadarMode(),dto.getRadarHight()); devicePropertiesOperateService.deviceWrite(dto.getDeviceId(),dto.getRadarMount(),dto.getRadarMode(),dto.getRadarHight());
} }
@Override
public List<DeviceProperties> readDeviceProperties(PlatDeviceAttrWechatDTO dto) {
List<DeviceProperties> devicePropertiesList = Lists.newArrayList();
if (StringUtils.isNotEmpty(dto.getReadProperties())) {
String[] propertiesArr = dto.getReadProperties().split(",");
for (String s : propertiesArr) {
DeviceProperties deviceProperties = devicePropertiesOperateService.deviceRead(dto.getDeviceId(), s);
if (deviceProperties != null) {
devicePropertiesList.add(deviceProperties);
}
}
}
return devicePropertiesList;
}
} }
...@@ -3,11 +3,13 @@ package com.makeit; ...@@ -3,11 +3,13 @@ package com.makeit;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling @EnableScheduling
@EnableAsync @EnableAsync
@ServletComponentScan
@MapperScan(basePackages = {"com.makeit.**.mapper"}) @MapperScan(basePackages = {"com.makeit.**.mapper"})
//@SpringBootApplication(scanBasePackages = {"com.makeit"}) //@SpringBootApplication(scanBasePackages = {"com.makeit"})
@SpringBootApplication @SpringBootApplication
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment