doum
3 天以前 3c7399c25c0f35c8aa7cb6af1935e31d1a3f0102
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceServiceImpl.java
@@ -99,6 +99,7 @@
        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);
@@ -187,6 +188,7 @@
                .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);
@@ -504,6 +506,7 @@
    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());
    }
@@ -612,6 +615,7 @@
        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 + "行所属项目不能为空,请检查表格内容!");
        }
@@ -668,6 +672,7 @@
        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);
@@ -697,6 +702,32 @@
        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;