Commit ae7793a35e268a03a3591dfa5f89dc72290a9c92

Authored by xp.Huang
1 parent d701c690

fix: Modbus命令下发参数校验

@@ -218,10 +218,18 @@ public class TkDeviceScriptController extends BaseController { @@ -218,10 +218,18 @@ public class TkDeviceScriptController extends BaseController {
218 throw new TkDataValidationException(String.format(ErrorMessage.NEED_MAIN_PARAMETER.getMessage(),"设备地址码")); 218 throw new TkDataValidationException(String.format(ErrorMessage.NEED_MAIN_PARAMETER.getMessage(),"设备地址码"));
219 } 219 }
220 if(StringUtils.isEmpty(inputParams.getMethod()) || null == inputParams.getCrc() || 220 if(StringUtils.isEmpty(inputParams.getMethod()) || null == inputParams.getCrc() ||
221 - null ==inputParams.getRegisterNumber() || null ==inputParams.getRegisterAddress() ||  
222 - null ==inputParams.getRegisterValues() || inputParams.getRegisterValues().isEmpty()){ 221 + null ==inputParams.getRegisterAddress()){
223 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 222 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
224 } 223 }
  224 + if(null !=inputParams.getRegisterNumber() && null !=inputParams.getRegisterValues() &&
  225 + !inputParams.getRegisterValues().isEmpty()){
  226 + List<Integer> registerValues = inputParams.getRegisterValues();
  227 + for (Integer value : registerValues){
  228 + if(null == value){
  229 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  230 + }
  231 + }
  232 + }
225 return ResponseEntity.ok(scriptService.modbus(inputParams)); 233 return ResponseEntity.ok(scriptService.modbus(inputParams));
226 } 234 }
227 235
@@ -23,9 +23,9 @@ public class TkDeviceRpcDTO implements Serializable { @@ -23,9 +23,9 @@ public class TkDeviceRpcDTO implements Serializable {
23 @ApiModelProperty(value = "寄存器地址", required = true) 23 @ApiModelProperty(value = "寄存器地址", required = true)
24 private Integer registerAddress; 24 private Integer registerAddress;
25 25
26 - @ApiModelProperty(value = "寄存器数量", required = true) 26 + @ApiModelProperty(value = "寄存器数量")
27 private Integer registerNumber; 27 private Integer registerNumber;
28 28
29 - @ApiModelProperty(value = "寄存器值", required = true) 29 + @ApiModelProperty(value = "寄存器值")
30 private List<Integer> registerValues; 30 private List<Integer> registerValues;
31 } 31 }