修改企业注册重复问题。

This commit is contained in:
sh
2026-02-02 17:54:52 +08:00
parent bb6e80ece6
commit 30faf7f933
3 changed files with 52 additions and 12 deletions

View File

@@ -31,4 +31,6 @@ public interface CompanyMapper extends BaseMapper<Company>
Company selectCompanyByJobId(Long jobId);
List<Company> selectByNames(List<String> list);
public Company selectByCode(@Param("code") String code);
}

View File

@@ -309,7 +309,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
handleUserTypeSpecificLogic(existingUser, registerBody);
// 5. 系统用户同步(不存在则创建)
syncSysUserIfNecessary(existingUser);
//syncSysUserIfNecessary(existingUser);
// 6. 一体机密码加密处理
encryptYtjPassword(existingUser);
@@ -363,6 +363,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
switch (userType) {
case StringUtil.IS_COMPANY_USER:
handleCompanyUserLogic(appUser, registerBody.getCompany());
appUser.setIdCard(registerBody.getCompany().getCode());
break;
default:
handleJobSeekerUserLogic(appUser, registerBody);
@@ -377,15 +378,22 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
*/
private void handleCompanyUserLogic(AppUser appUser, Company company) {
if (company != null) {
// 保存企业信息(新增场景)
if (company.getCompanyId() == null) {
companyMapper.insert(company);
// 批量保存企业联系人
saveCompanyContacts(company.getCompanyId(), company.getCompanyContactList());
Company resultCom=companyMapper.selectByCode(company.getCode());
if(resultCom==null){
// 保存企业信息(新增场景)
if (company.getCompanyId() == null) {
companyMapper.insert(company);
// 批量保存企业联系人
saveCompanyContacts(company.getCompanyId(), company.getCompanyContactList());
}
// 关联企业信息到用户
appUser.setIdCard(company.getCode());
appUser.setName(company.getName());
}else{
company.setCompanyId(resultCom.getCompanyId());
companyMapper.updateById(company);
saveCompanyContacts(resultCom.getCompanyId(), company.getCompanyContactList());
}
// 关联企业信息到用户
appUser.setIdCard(company.getCode());
appUser.setName(company.getName());
}
}
@@ -395,9 +403,31 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
* @param contactList 联系人列表
*/
private void saveCompanyContacts(Long companyId, List<CompanyContact> contactList) {
if (contactList != null && !contactList.isEmpty()) {
contactList.forEach(contact -> contact.setCompanyId(companyId));
companyContactMapper.batchInsert(contactList);
//查询联系人
CompanyContact parm=new CompanyContact();
parm.setCompanyId(companyId);
List<CompanyContact> existingContacts =companyContactMapper.getSelectList(parm);
Set<String> existingContactKeySet = (existingContacts == null || existingContacts.isEmpty())
? new HashSet<>()
: existingContacts.stream()
.filter(existing -> existing.getContactPerson() != null
&& existing.getContactPersonPhone() != null
&& existing.getCompanyId() != null)
.map(existing -> existing.getContactPerson() + "_" + existing.getContactPersonPhone() + "_" + existing.getCompanyId())
.collect(Collectors.toSet());
List<CompanyContact> toInsertContactList = contactList.stream()
.peek(contact -> contact.setCompanyId(companyId))
.filter(contact -> contact.getContactPerson() != null
&& contact.getContactPersonPhone() != null
&& contact.getCompanyId() != null)
.filter(contact -> {
String currentUniqueKey = contact.getContactPerson() + "_" + contact.getContactPersonPhone() + "_" + contact.getCompanyId();
return !existingContactKeySet.contains(currentUniqueKey);
})
.collect(Collectors.toList());
if (!toInsertContactList.isEmpty()) {
companyContactMapper.batchInsert(toInsertContactList);
}
}

View File

@@ -121,4 +121,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</select>
<select id="selectByCode" resultType="com.ruoyi.common.core.domain.entity.Company">
<include refid="selectCompanyVo"/>
<where> del_flag = '0'
<if test="code != null and code != ''"> AND UPPER(code) = UPPER(#{code})</if>
</where>
order by create_time desc limit 1
</select>
</mapper>