feat: Refactor company and job management to include company nature

- Added companyNature field to Company entity and updated related services and mappers.
- Removed jobNature field from Job and ESJobDocument entities as it is no longer needed.
- Updated CompanyController to handle current company information and synchronization of account codes.
- Enhanced CompanyServiceImpl to manage company nature changes and synchronize related job postings.
- Updated SQL migrations to add company nature field and associated business dictionary entries.
- Refactored job-related services to ensure they reflect the latest company nature information.
This commit is contained in:
2026-07-16 15:05:53 +08:00
parent 3f1624da3a
commit acb0762dcc
17 changed files with 378 additions and 135 deletions

View File

@@ -3,9 +3,12 @@ package com.ruoyi.cms.controller.cms;
import com.ruoyi.cms.domain.query.CompanySearch;
import com.ruoyi.cms.domain.query.JobSearch;
import com.ruoyi.cms.mapper.AppUserMapper;
import com.ruoyi.cms.util.RoleUtils;
import com.ruoyi.cms.util.sensitiveWord.SensitiveWordChecker;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.common.core.domain.entity.Company;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.cms.service.ICompanyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
@@ -13,7 +16,10 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +44,12 @@ public class CompanyController extends BaseController
@Autowired
private ICompanyService companyService;
@Autowired
private AppUserMapper appUserMapper;
@Autowired
private ISysUserService sysUserService;
@Autowired
SensitiveWordChecker sensitiveWordChecker;
@@ -50,10 +62,10 @@ public class CompanyController extends BaseController
public TableDataInfo list(CompanySearch company)
{
if (RoleUtils.isCompanyAdmin()) {
System.out.println("企业社会信用代码============================="+RoleUtils.getCurrentUseridCard());
if(StringUtils.isNotEmpty(RoleUtils.getCurrentUseridCard())){
company.setCode(RoleUtils.getCurrentUseridCard());
}else{
Company currentCompany = getCurrentCompany();
if (currentCompany != null) {
company.setCompanyId(currentCompany.getCompanyId());
} else {
return getDataTable(new ArrayList<>());
}
}
@@ -87,6 +99,21 @@ public class CompanyController extends BaseController
return success(companyService.selectCompanyByCompanyId(companyId));
}
/**
* 获取当前企业账号关联的企业信息。
*/
@ApiOperation("获取当前企业信息")
@PreAuthorize("@ss.hasPermi('cms:company:query')")
@GetMapping("/current")
public AjaxResult getCurrentInfo()
{
Company company = getCurrentCompany();
if (company == null) {
return AjaxResult.error("未查询到当前企业信息");
}
return success(companyService.selectCompanyByCompanyId(company.getCompanyId()));
}
/**
* 新增公司
*/
@@ -115,6 +142,8 @@ public class CompanyController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody Company company)
{
Company existingCompany = company.getCompanyId() == null
? null : companyService.selectCompanyByCompanyId(company.getCompanyId());
// 校验描述中的敏感词
List<String> sensitiveWords = sensitiveWordChecker.checkSensitiveWords(company.getDescription());
if (!sensitiveWords.isEmpty()) {
@@ -122,7 +151,104 @@ public class CompanyController extends BaseController
return AjaxResult.error(errorMsg, sensitiveWords);
}
// 无敏感词,执行插入
return toAjax(companyService.updateCompany(company));
AjaxResult result = toAjax(companyService.updateCompany(company));
if (result.get("code") instanceof Number && ((Number) result.get("code")).intValue() == 200
&& existingCompany != null && company.getCode() != null
&& !java.util.Objects.equals(existingCompany.getCode(), company.getCode())) {
syncAccountCode(existingCompany.getCode(), company.getCode(), null);
}
return result;
}
/**
* 修改当前企业账号关联的企业信息企业ID由登录账号确定不能由前端指定其他企业。
*/
@ApiOperation("修改当前企业信息")
@PreAuthorize("@ss.hasPermi('cms:company:edit')")
@PutMapping("/current")
public AjaxResult editCurrent(@RequestBody Company company)
{
Company currentCompany = getCurrentCompany();
if (currentCompany == null) {
return AjaxResult.error("未查询到当前企业信息");
}
String oldCode = currentCompany.getCode();
company.setCompanyId(currentCompany.getCompanyId());
// 将企业和当前企业账号建立稳定的 user_id 关联,信用代码修改后仍能找到企业。
Long appUserId = RoleUtils.getSysAppuserId();
if (appUserId != null) {
company.setUserId(appUserId);
}
AjaxResult result = edit(company);
if (result.get("code") instanceof Number && ((Number) result.get("code")).intValue() == 200
&& StringUtils.isEmpty(oldCode) && company.getCode() != null) {
syncAccountCode(oldCode, company.getCode(), SecurityUtils.getLoginUser().getUser());
}
return result;
}
private Company getCurrentCompany()
{
if (!RoleUtils.isCompanyAdmin()) {
return null;
}
String currentCode = RoleUtils.getCurrentUseridCard();
if (StringUtils.isNotEmpty(currentCode)) {
Company company = companyService.queryCodeCompany(currentCode);
if (company != null) {
return company;
}
}
// 兼容历史数据:部分企业记录没有 company.user_id先通过 app_user_id 查到企业账号。
Long appUserId = RoleUtils.getSysAppuserId();
if (appUserId != null) {
CompanySearch search = new CompanySearch();
search.setUserId(appUserId);
List<Company> companies = companyService.selectCompanyList(search);
if (companies != null && !companies.isEmpty()) {
return companyService.selectCompanyByCompanyId(companies.get(0).getCompanyId());
}
// 兼容信用代码已被修改但账号缓存仍是旧值的场景。
AppUser appUser = appUserMapper.selectById(appUserId);
if (appUser != null && StringUtils.isNotEmpty(appUser.getIdCard())) {
return companyService.queryCodeCompany(appUser.getIdCard());
}
}
return null;
}
/**
* 企业修改信用代码后同步 PC/APP 账号关联,避免后续岗位等企业端接口仍使用旧代码。
*/
private void syncAccountCode(String oldCode, String newCode, SysUser fallbackUser)
{
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
SysUser sysUser = StringUtils.isNotEmpty(oldCode)
? sysUserService.selectUserByIdCard(oldCode) : fallbackUser;
if (sysUser != null) {
SysUser updateUser = new SysUser();
updateUser.setUserId(sysUser.getUserId());
updateUser.setIdCard(newCode);
sysUserService.updateUserProfile(updateUser);
// 当前请求中的登录对象可能仍是缓存实例,立即更新它以便本次请求链路保持一致。
if (currentUser != null && java.util.Objects.equals(currentUser.getUserId(), sysUser.getUserId())) {
currentUser.setIdCard(newCode);
}
}
AppUser appUser = sysUser == null || sysUser.getAppUserId() == null
? appUserMapper.selectOne(Wrappers.<AppUser>lambdaQuery().eq(AppUser::getIdCard, oldCode)
.eq(AppUser::getDelFlag, "0").last("LIMIT 1"))
: appUserMapper.selectById(sysUser.getAppUserId());
if (appUser == null && fallbackUser != null && currentUser != null && currentUser.getAppUserId() != null) {
appUser = appUserMapper.selectById(currentUser.getAppUserId());
}
if (appUser != null) {
appUser.setIdCard(newCode);
appUserMapper.updateById(appUser);
}
}
/**

View File

@@ -120,9 +120,6 @@ public class ESJobDocument
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
private String jobCategory;
@ApiModelProperty("岗位性质,对应业务字典 job_nature")
private String jobNature;
@JsonIgnore
@ApiModelProperty("学历要求 对应字典education int类型 es方便查询")
private Integer education_int;

View File

@@ -148,10 +148,6 @@ public class Job extends BaseEntity
@ApiModelProperty("岗位分类")
private String jobCategory;
@Excel(name = "岗位性质")
@ApiModelProperty("岗位性质,对应业务字典 job_nature")
private String jobNature;
@TableField(exist = false)
@ApiModelProperty("公司性质")
private String companyNature;

View File

@@ -242,7 +242,6 @@ public class BussinessDictTypeServiceImpl implements IBussinessDictTypeService
filed.put("data_source","数据来源");
filed.put("job_url","岗位url连接");
filed.put("job_category",jobTitleMapper.selectList(null).stream().map(JobTitle::getJobName).collect(Collectors.toList()));
filed.put("job_nature",this.selectDictDataByType("job_nature").stream().map(BussinessDictData::getDictLabel).collect(Collectors.toList()));
return filed;
}
}

View File

@@ -155,6 +155,11 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
@Override
public int updateCompany(Company company)
{
Company existingCompany = company.getCompanyId() == null
? null : companyMapper.selectById(company.getCompanyId());
boolean companyNatureChanged = existingCompany != null
&& company.getCompanyNature() != null
&& !Objects.equals(existingCompany.getCompanyNature(), company.getCompanyNature());
Long count = companyMapper.selectCount(Wrappers.<Company>lambdaQuery().eq(Company::getName, company.getName()));
if(count>1){
throw new ServiceException(company.getName()+",该公司已存在");
@@ -164,12 +169,23 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
companyContactMapper.update(null,Wrappers.<CompanyContact>lambdaUpdate()
.eq(CompanyContact::getCompanyId, company.getCompanyId())
.set(CompanyContact::getDelFlag, Constants.Del_FLAG_DELETE));
if(Objects.isNull(company.getCompanyContactList())){return i;}
company.getCompanyContactList().forEach(x -> {
CompanyContact companyContact = new CompanyContact();
companyContact.setCompanyId(company.getCompanyId());
companyContactMapper.insert(companyContact);
});
if(!Objects.isNull(company.getCompanyContactList())){
company.getCompanyContactList().forEach(x -> {
CompanyContact companyContact = new CompanyContact();
companyContact.setCompanyId(company.getCompanyId());
BeanUtils.copyProperties(x, companyContact);
companyContactMapper.insert(companyContact);
});
}
if (companyNatureChanged) {
List<Long> jobIds = jobMapper.selectList(Wrappers.<Job>lambdaQuery()
.eq(Job::getCompanyId, company.getCompanyId()))
.stream()
.map(Job::getJobId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
iesJobSearchService.batchUpdateJob(jobIds);
}
}
return i;
}

View File

@@ -220,9 +220,6 @@ public class ESJobSearchImpl implements IESJobSearchService
if (esJobDocument.getLatitude() != null) {
esJobDocument.setLatAndLon(esJobDocument.getLatitude().toString() + "," + esJobDocument.getLongitude().toString());
}
if(StringUtil.isEmptyOrNull(job.getCompanyNature())){
esJobDocument.setCompanyNature("4");
}
if (StringUtils.isNotEmpty(job.getPostingDate())) {
Date date = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,job.getPostingDate());
esJobDocument.setPostingDate(date);
@@ -927,7 +924,10 @@ public class ESJobSearchImpl implements IESJobSearchService
if(job!=null){
if(job.getCompanyId()!=null){
Company company=iCompanyService.selectCompanyByCompanyId(job.getCompanyId());
job.setCode(company.getCode());
if (company != null) {
job.setCode(company.getCode());
job.setCompanyNature(company.getCompanyNature());
}
}
}
@@ -954,9 +954,6 @@ public class ESJobSearchImpl implements IESJobSearchService
if (esJobDocument.getLatitude() != null) {
esJobDocument.setLatAndLon(esJobDocument.getLatitude().toString() + "," + esJobDocument.getLongitude().toString());
}
if(StringUtil.isEmptyOrNull(job.getCompanyNature())){
esJobDocument.setCompanyNature("4");
}
ensureJobDocumentIndexExists();
LambdaEsQueryWrapper<ESJobDocument> lambdaEsQueryWrapper = new LambdaEsQueryWrapper();
@@ -1202,6 +1199,7 @@ public class ESJobSearchImpl implements IESJobSearchService
Company company = companyMap.get(job.getCompanyId());
if (company != null) {
esDoc.setCode(company.getCode());
esDoc.setCompanyNature(company.getCompanyNature());
}
}
@@ -1231,11 +1229,6 @@ public class ESJobSearchImpl implements IESJobSearchService
esDoc.setLatAndLon(esDoc.getLatitude() + "," + esDoc.getLongitude());
}
// 企业行业默认值
if (StringUtil.isEmptyOrNull(job.getCompanyNature())) {
esDoc.setCompanyNature("4");
}
return esDoc;
}

View File

@@ -456,7 +456,7 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
//添加附件
handleJobFile(job);
// 数据库更新成功后再同步 ES确保岗位性质等最新字段能立即反映到 PC 岗位卡片。
// 数据库更新成功后再同步 ES确保关联企业性质等最新字段能立即反映到 PC 岗位卡片。
if (Integer.valueOf(1).equals(job.getIsPublish())
|| (job.getIsPublish() == null && existingJob != null
&& Integer.valueOf(1).equals(existingJob.getIsPublish()))) {