| | |
| | | if(ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO).eq(YwDevice::getCode,ywDevice.getCode()))>Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"设备编号重复!"); |
| | | } |
| | | ywDevice.setDeviceNum(normalizeDeviceNum(ywDevice.getDeviceNum())); |
| | | ywDevice.setCreateDate(new Date()); |
| | | ywDevice.setCreator(loginUserInfo.getId()); |
| | | ywDevice.setIsdeleted(Constants.ZERO); |
| | |
| | | .ne(YwDevice::getId,ywDevice.getId()))>Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"设备编号重复!"); |
| | | } |
| | | ywDevice.setDeviceNum(normalizeDeviceNum(ywDevice.getDeviceNum())); |
| | | ywDevice.setEditDate(new Date()); |
| | | ywDevice.setEditor(loginUserInfo.getId()); |
| | | ywDeviceMapper.updateById(ywDevice); |
| | |
| | | private boolean isImportBlankRow(DeviceImport row) { |
| | | return StringUtils.isBlank(row.getCode()) |
| | | && StringUtils.isBlank(row.getName()) |
| | | && StringUtils.isBlank(row.getDeviceNum()) |
| | | && StringUtils.isBlank(row.getProjectName()) |
| | | && StringUtils.isBlank(row.getRoomPath()); |
| | | } |
| | |
| | | if (StringUtils.isBlank(row.getName())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + rowNum + "行设备名称不能为空,请检查表格内容!"); |
| | | } |
| | | Integer deviceNum = parseImportDeviceNum(row.getDeviceNum(), rowNum); |
| | | if (StringUtils.isBlank(row.getProjectName())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + rowNum + "行所属项目不能为空,请检查表格内容!"); |
| | | } |
| | |
| | | YwDevice device = new YwDevice(); |
| | | device.setCode(code); |
| | | device.setName(row.getName().trim()); |
| | | device.setDeviceNum(deviceNum); |
| | | device.setCateId(cateId); |
| | | device.setModelNo(StringUtils.trimToNull(row.getModelNo())); |
| | | device.setUserId(userId); |
| | |
| | | return device; |
| | | } |
| | | |
| | | private Integer normalizeDeviceNum(Integer deviceNum) { |
| | | if (deviceNum == null || deviceNum <= 0) { |
| | | return 1; |
| | | } |
| | | return deviceNum; |
| | | } |
| | | |
| | | private Integer parseImportDeviceNum(String deviceNumText, int rowNum) { |
| | | if (StringUtils.isBlank(deviceNumText)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + rowNum + "行设备数量不能为空,请检查表格内容!"); |
| | | } |
| | | String text = deviceNumText.trim(); |
| | | if (StringUtils.endsWith(text, ".0")) { |
| | | text = StringUtils.substringBefore(text, ".0"); |
| | | } |
| | | try { |
| | | double value = Double.parseDouble(text); |
| | | if (value <= 0 || value != Math.floor(value)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + rowNum + "行设备数量必须为正整数,请检查表格内容!"); |
| | | } |
| | | return (int) value; |
| | | } catch (NumberFormatException e) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,第" + rowNum + "行设备数量必须为正整数,请检查表格内容!"); |
| | | } |
| | | } |
| | | |
| | | private Integer resolveInternalUserId(String userName, int rowNum, String fieldLabel, DeviceImportCache cache) { |
| | | if (StringUtils.isBlank(userName)) { |
| | | return null; |