Commit a7f70342190b4edbb45ac43c811bc6c7955b2a0c

Authored by xp.Huang
2 parents 267b5ff5 45fed0b1

Merge branch 'fix_webcam' into 'master_dev'

Fix webcam

See merge request yunteng/thingskit!398
... ... @@ -3,6 +3,9 @@ package org.thingsboard.server.controller.yunteng;
3 3 import org.springframework.http.ResponseEntity;
4 4 import org.springframework.web.bind.annotation.*;
5 5 import org.springframework.web.multipart.MultipartFile;
  6 +import org.thingsboard.server.common.data.StringUtils;
  7 +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
  8 +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
6 9 import org.thingsboard.server.common.data.yunteng.core.utils.FileStorageService;
7 10 import org.thingsboard.server.common.data.yunteng.dto.FileUploadResponse;
8 11
... ... @@ -29,4 +32,11 @@ public class TkOssFileController {
29 32 @PathVariable String fileName, HttpServletRequest request, HttpServletResponse response) {
30 33 return fileStorageService.download(fileName, request, response);
31 34 }
  35 + @DeleteMapping
  36 + public ResponseEntity<Boolean> deleteFile(@RequestParam("deleteFilePath") String deleteFilePath){
  37 + if(StringUtils.isEmpty(deleteFilePath)){
  38 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  39 + }
  40 + return ResponseEntity.ok(fileStorageService.deleteFile(deleteFilePath));
  41 + }
32 42 }
... ...
... ... @@ -28,4 +28,6 @@ public interface FileStorageService {
28 28 String fileName, HttpServletRequest request, HttpServletResponse response);
29 29
30 30 String uploadFile(String fileName, String contentType, InputStream inputStream) throws Exception;
  31 +
  32 + boolean deleteFile(String deleteFilePath);
31 33 }
... ...
... ... @@ -131,6 +131,12 @@ public class LocalFileStorageService implements FileStorageService {
131 131 return ossStaticPath;
132 132 }
133 133
  134 + @Override
  135 + public boolean deleteFile(String deleteFilePath) {
  136 + //TODO delete local file or delete datafile
  137 + return false;
  138 + }
  139 +
134 140 private String storeFileByInputStream(String fileName, InputStream inputStream)
135 141 throws IOException {
136 142 // random fileName if needed
... ...
... ... @@ -16,6 +16,7 @@ import org.springframework.util.StringUtils;
16 16 import org.springframework.web.context.request.RequestContextHolder;
17 17 import org.springframework.web.context.request.ServletRequestAttributes;
18 18 import org.springframework.web.multipart.MultipartFile;
  19 +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
19 20 import org.thingsboard.server.common.data.yunteng.core.exception.FileStorageException;
20 21 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
21 22 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
... ... @@ -173,6 +174,25 @@ public class MinioFileStorageService implements FileStorageService {
173 174 }
174 175 }
175 176
  177 + @Override
  178 + public boolean deleteFile(String deleteFilePath) {
  179 + boolean result =false;
  180 + try{
  181 + String bucketName = fileStorageProperties.getBucketName();
  182 + int one = FastIotConstants.MagicNumber.ONE;
  183 + String[] split = deleteFilePath.split(bucketName + "/");
  184 + if(split.length>one){
  185 + deleteFilePath = split[one];
  186 + }
  187 + minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName)
  188 + .object(deleteFilePath).build());
  189 + result = true;
  190 + }catch (Exception e){
  191 + log.error("文件删除失败:{}",deleteFilePath);
  192 + }
  193 + return result;
  194 + }
  195 +
176 196 private void checkBucket()
177 197 throws ServerException, InsufficientDataException, ErrorResponseException, IOException,
178 198 NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException,
... ...
... ... @@ -16,7 +16,8 @@ public class TkDataViewContentInfoDTO {
16 16 private Integer state;
17 17 @ApiModelProperty(value = "组织ID")
18 18 private String organizationId;
19   -
  19 + @ApiModelProperty(value = "缩略图")
  20 + private String thumbnail;
20 21 @ApiModelProperty(value = "大屏内容",required = true)
21 22 private TkDataViewContentDTO dataViewContent;
22 23 }
... ...
1 1 package org.thingsboard.server.common.data.yunteng.utils;
2 2
  3 +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
3 4 import org.thingsboard.server.common.data.yunteng.enums.AttributeSourceDataTypeEnum;
4 5 import org.thingsboard.server.common.data.yunteng.enums.HexByteOrderEnum;
5 6 import java.nio.ByteOrder;
... ... @@ -252,7 +253,11 @@ public class HexConvertUtils {
252 253 case INT16_BA:
253 254 case UINT16_BA:
254 255 hex = convertHexOrder(hex, dataTypeEnum);
255   - value = intFormat.format(int16OrUint16ToShort(hex) * scaleFactor);
  256 + if((int16OrUint16ToShort(hex) * scaleFactor) % 1 == FastIotConstants.MagicNumber.ZERO){
  257 + value = int16OrUint16ToShort(hex);
  258 + }else{
  259 + value = intFormat.format(int16OrUint16ToShort(hex) * scaleFactor);
  260 + }
256 261 break;
257 262 case INT32_AB_CD:
258 263 case UINT32_AB_CD:
... ...
... ... @@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
13 13 import org.thingsboard.common.util.JacksonUtil;
14 14 import org.thingsboard.server.common.adaptor.AdaptorException;
15 15 import org.thingsboard.server.common.data.DataConstants;
  16 +import org.thingsboard.server.common.data.Device;
16 17 import org.thingsboard.server.common.data.DeviceProfile;
17 18 import org.thingsboard.server.common.data.DeviceTransportType;
18 19 import org.thingsboard.server.common.data.device.profile.TkTcpDeviceProfileTransportConfiguration;
... ... @@ -138,7 +139,6 @@ public class TcpUdpDataHandler implements SessionMsgListener {
138 139 }
139 140 deviceSessionCtx.tryProcessQueuedMsgs(msg -> processDeviceSessionMsg(ctx, msg));
140 141 }
141   -
142 142 private void processAuthTokenConnect(ChannelHandlerContext ctx, TcpAuthEntry accessToken) {
143 143
144 144 log.debug(
... ... @@ -519,6 +519,20 @@ public class TcpUdpDataHandler implements SessionMsgListener {
519 519 }
520 520
521 521 @Override
  522 + public void onDeviceProfileUpdate(
  523 + TransportProtos.SessionInfoProto sessionInfo, DeviceProfile deviceProfile) {
  524 + deviceSessionCtx.onDeviceProfileUpdate(sessionInfo, deviceProfile);
  525 + }
  526 +
  527 + @Override
  528 + public void onDeviceUpdate(
  529 + TransportProtos.SessionInfoProto sessionInfo,
  530 + Device device,
  531 + Optional<DeviceProfile> deviceProfileOpt) {
  532 + deviceSessionCtx.onDeviceUpdate(sessionInfo, device, deviceProfileOpt);
  533 + deviceSessionCtx.setDeviceCode(JacksonUtil.toString(device.getAdditionalInfo()));
  534 + }
  535 + @Override
522 536 public void onDeviceDeleted(DeviceId deviceId) {
523 537 context.onAuthFailure(address);
524 538 if (isTcp) {
... ...
... ... @@ -24,6 +24,7 @@
24 24
25 25 <resultMap id="dataViewInfoMap"
26 26 type="org.thingsboard.server.common.data.yunteng.dto.request.TkDataViewContentInfoDTO">
  27 + <result property="thumbnail" column="thumbnail"/>
27 28 <result property="dataViewId" column="id"/>
28 29 <result property="dataViewName" column="name"/>
29 30 <result property="state" column="state"/>
... ... @@ -61,7 +62,7 @@
61 62 </select>
62 63
63 64 <select id="getDataViewInfoById" resultMap="dataViewInfoMap">
64   - SELECT icc.id,icc.name,icc.state,icc.organization_id,icc.thumbnail,icct.id AS content_id,icct.content FROM tk_data_view icc LEFT JOIN
  65 + SELECT icc.id,icc.thumbnail,icc.name,icc.state,icc.organization_id,icc.thumbnail,icct.id AS content_id,icct.content FROM tk_data_view icc LEFT JOIN
65 66 tk_data_view_content icct ON icc.id = icct.view_id
66 67 WHERE icc.id = #{id} AND icc.tenant_id = #{tenantId}
67 68 </select>
... ...