Commit 4c71b7d93b82cc2f9c784d2ef3683121009bb7b2
1 parent
6c24e4f6
fix: delete data component and check parameter
Showing
1 changed file
with
10 additions
and
10 deletions
@@ -103,21 +103,21 @@ public class YtDataComponentController extends BaseController { | @@ -103,21 +103,21 @@ public class YtDataComponentController extends BaseController { | ||
103 | throws ThingsboardException { | 103 | throws ThingsboardException { |
104 | String tenantId = getCurrentUser().getCurrentTenantId(); | 104 | String tenantId = getCurrentUser().getCurrentTenantId(); |
105 | deleteDTO.setTenantId(tenantId); | 105 | deleteDTO.setTenantId(tenantId); |
106 | + | ||
107 | + DataBoardDTO dataBoardDTO = ytDataBoardService.findDataBoardInfoById(dataBoardId, tenantId); | ||
108 | + if (null == dataBoardDTO) { | ||
109 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
110 | + } | ||
106 | int deleteNum = ytDataComponentService.deleteDataComponent(deleteDTO); | 111 | int deleteNum = ytDataComponentService.deleteDataComponent(deleteDTO); |
107 | 112 | ||
108 | int zero = FastIotConstants.MagicNumber.ZERO; | 113 | int zero = FastIotConstants.MagicNumber.ZERO; |
109 | boolean result = deleteNum > zero; | 114 | boolean result = deleteNum > zero; |
110 | if (result) { | 115 | if (result) { |
111 | - DataBoardDTO dataBoardDTO = ytDataBoardService.findDataBoardInfoById(dataBoardId, tenantId); | ||
112 | - if (null != dataBoardDTO) { | ||
113 | - int count = | ||
114 | - dataBoardDTO.getComponentNum() != null | ||
115 | - ? dataBoardDTO.getComponentNum() - deleteNum < zero | ||
116 | - ? zero | ||
117 | - : dataBoardDTO.getComponentNum() - deleteNum | ||
118 | - : zero; | ||
119 | - ytDataBoardService.updateDataBoardComponentNum(dataBoardId, tenantId, count); | ||
120 | - } | 116 | + int count = |
117 | + dataBoardDTO.getComponentNum() != null | ||
118 | + ? Math.max(dataBoardDTO.getComponentNum() - deleteNum, zero) | ||
119 | + : zero; | ||
120 | + ytDataBoardService.updateDataBoardComponentNum(dataBoardId, tenantId, count); | ||
121 | } | 121 | } |
122 | return ResponseResult.success(result); | 122 | return ResponseResult.success(result); |
123 | } | 123 | } |