{"record":{"id":"77d7b804789a9d10","repo":"elunez/eladmin","slug":"user-with-phone-existed","errorCode":null,"errorMessage":"User with phone {} existed","messagePattern":"User with phone (.+?) existed","errorType":"exception","errorClass":"EntityExistException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java","lineNumber":95,"sourceCode":"        if (user == null) {\n            user = userRepository.findById(id).orElseGet(User::new);\n            ValidationUtil.isNull(user.getId(), \"User\", \"id\", id);\n            redisUtils.set(key, user, 1, TimeUnit.DAYS);\n        }\n        return userMapper.toDto(user);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void create(User resources) {\n        if (userRepository.findByUsername(resources.getUsername()) != null) {\n            throw new EntityExistException(User.class, \"username\", resources.getUsername());\n        }\n        if (userRepository.findByEmail(resources.getEmail()) != null) {\n            throw new EntityExistException(User.class, \"email\", resources.getEmail());\n        }\n        if (userRepository.findByPhone(resources.getPhone()) != null) {\n            throw new EntityExistException(User.class, \"phone\", resources.getPhone());\n        }\n        resources.setIsAdmin(false);\n        userRepository.save(resources);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void update(User resources) throws Exception {\n        User user = userRepository.findById(resources.getId()).orElseGet(User::new);\n        ValidationUtil.isNull(user.getId(), \"User\", \"id\", resources.getId());\n        User user1 = userRepository.findByUsername(resources.getUsername());\n        User user2 = userRepository.findByEmail(resources.getEmail());\n        User user3 = userRepository.findByPhone(resources.getPhone());\n        if (user1 != null && !user.getId().equals(user1.getId())) {\n            throw new EntityExistException(User.class, \"username\", resources.getUsername());\n        }\n        if (user2 != null && !user.getId().equals(user2.getId())) {\n            throw new EntityExistException(User.class, \"email\", resources.getEmail());","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java#L77-L113","documentation":"EntityExistException thrown in UserServiceImpl.create when the phone number is already used by another user. Third and last uniqueness gate in create (after username and email); findByPhone returning any row rejects the new account.","triggerScenarios":"POST /api/users with a mobile number that exists on any other account.","commonSituations":"Ex-employees' accounts kept active while re-onboarding the same person; test accounts created with dummy phone '13800138000' colliding; bulk imports with duplicated phone columns.","solutions":["Assign a distinct phone number to the new account.","Update or delete the old account that holds the number first.","Deduplicate phone numbers in import spreadsheets before running the import."],"exampleFix":"// before\nuser.setPhone(\"13800138000\"); // classic dummy, already used\n\n// after\nuser.setPhone(\"13900001111\");","handlingStrategy":"validation","validationCode":"if (userRepository.findByPhone(form.phone) != null) { errors.phone = '手机号已被使用'; return; }","typeGuard":"const isUnique = (p: string, users: {phone:string}[]) => !users.some(u => u.phone === p);","tryCatchPattern":"catch (EntityExistException e) { if (e.getMessage().startsWith(\"User with phone\")) errors.phone = '手机号已被占用'; }","preventionTips":["Ban shared dummy numbers like 13800138000 in test data","Strip/deduplicate phone columns before bulk import","Unique-check phone alongside email in the create form"],"tags":["eladmin","user","duplicate","phone","create"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}