重构此方法以将其认知复杂度从19降低到15

时间:2019-12-31 05:25:03

标签: java spring spring-boot

private void regulationtDuplicateValid(RegulationDTO regulationDto, List<Object[]> resultSetCount)
            throws ERPException {
        for (Object[] object : resultSetCount) {

            Long regId = null;
            String regName = null;
            String regFullName = null;
            String regShortName = null;
            if (object[0] != null || object[1] != null || object[2] != null || object[3] != null) {

                regId = (Long) object[1];
                regName = (String) object[2];
                regFullName = (String) object[3];
                regShortName = (String) object[4];
                if (!(regId.equals(regulationDto.getRegId()))) {
                    if (regName.equalsIgnoreCase(regulationDto.getRegName())) {
                        throw new ERPException(ExaminationEnumApiErrorCode.getResponseCode(DUPLICATE_REGULATION_NAME));
                    }

                    if (regFullName.equalsIgnoreCase(regulationDto.getRegFullName())) {
                        throw new ERPException(
                                ExaminationEnumApiErrorCode.getResponseCode(DUPLICATE_REGULATION_FULL_NAME));
                    }

                    if (regShortName.equalsIgnoreCase(regulationDto.getRegShortName())) {
                        throw new ERPException(
                                ExaminationEnumApiErrorCode.getResponseCode(DUPLICATE_REGULATION_SHORT_NAME));

                    }
                }
            }

        }
    }

0 个答案:

没有答案
豫ICP备18024241号-1