{"record":{"id":"3b2aa4f87d691687","repo":"elunez/eladmin","slug":"error-3b2aa4","errorCode":null,"errorMessage":"所选的岗位中存在用户关联，请解除关联再试！","messagePattern":"所选的岗位中存在用户关联，请解除关联再试！","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/JobServiceImpl.java","lineNumber":125,"sourceCode":"    }\n\n    @Override\n    public void download(List<JobDto> jobDtos, HttpServletResponse response) throws IOException {\n        List<Map<String, Object>> list = new ArrayList<>();\n        for (JobDto jobDTO : jobDtos) {\n            Map<String,Object> map = new LinkedHashMap<>();\n            map.put(\"岗位名称\", jobDTO.getName());\n            map.put(\"岗位状态\", jobDTO.getEnabled() ? \"启用\" : \"停用\");\n            map.put(\"创建日期\", jobDTO.getCreateTime());\n            list.add(map);\n        }\n        FileUtil.downloadExcel(list, response);\n    }\n\n    @Override\n    public void verification(Set<Long> ids) {\n        if(userRepository.countByJobs(ids) > 0){\n            throw new BadRequestException(\"所选的岗位中存在用户关联，请解除关联再试！\");\n        }\n    }\n\n    /**\n     * 删除缓存\n     * @param id /\n     */\n    public void delCaches(Long id){\n        redisUtils.del(CacheKey.JOB_ID + id);\n    }\n}\n","sourceCodeStart":107,"sourceCodeEnd":137,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/JobServiceImpl.java#L107-L137","documentation":"Thrown by JobServiceImpl.verification when deleting jobs that are still referenced by users. It first counts users whose jobs collection intersects the given ids (userRepository.countByJobs); if any user is still assigned one of the jobs, deletion is blocked. This is referential-integrity protection so users are never left pointing at a deleted job. It surfaces as a 400 Bad Request via the global exception handler.","triggerScenarios":"Calling DELETE /api/jobs with a set of job ids where at least one id appears in some user's job list (job_user join table has rows). The frontend job list 'delete' action after selecting one or more jobs.","commonSituations":"Seeding/demo data that assigns jobs to the admin user; trying to clear default jobs before migrating job data; batch-cleaning jobs after an organizational restructure without first reassigning users.","solutions":["Open the user management page, filter users by the job in question, and clear/reassign that job on each user before deleting.","Alternatively delete or update the offending rows in the sys_users_jobs join table directly (SQL), then retry the delete.","If bulk cleanup is intended, write a maintenance script/SQL that first sets users_jobs references to NULL or removes them, then deletes the jobs.","In the UI, the verification endpoint /api/jobs/multi can be probed first so the user gets this message before a destructive call."],"exampleFix":"-- before: delete fails because users still reference job 5\nDELETE FROM sys_job WHERE job_id = 5; -- app blocks it\n\n-- after: remove user associations first, then delete\nDELETE FROM sys_users_jobs WHERE job_id = 5;\nDELETE FROM sys_job WHERE job_id = 5;","handlingStrategy":"validation","validationCode":"// Before showing Delete, ask the backend verification endpoint\nGET /api/jobs/multi?ids=1,2,3\n// 200 → safe to delete; 400 with message → block button and show which users hold the job","typeGuard":null,"tryCatchPattern":"catch (BadRequestException e) when (e.getMessage().contains(\"岗位中存在用户关联\")) { // surface user reassignment dialog }","preventionTips":["Probe /api/jobs/multi before enabling the delete action","Establish workflow: reassign users' jobs before deleting a job","Keep seed jobs unassigned or dedicate them to test users only"],"tags":["eladmin","job","referential-integrity","delete","spring-boot"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}