添加行业转换方法

This commit is contained in:
sh
2026-07-28 13:38:39 +08:00
parent 68835d10a3
commit 40a7e1db5e
4 changed files with 103 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.ruoyi.cms.util.dict.IndustryCacheUtil;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.ArrayList;
@@ -62,6 +63,9 @@ public class CompanyController extends BaseController
} }
startPage(); startPage();
List<Company> list = companyService.selectCompanyList(company); List<Company> list = companyService.selectCompanyList(company);
// list.forEach(item -> {
// item.setIndustryName(IndustryCacheUtil.getIndustryMatchName(item.getIndustryCode()));
// });
return getDataTable(list); return getDataTable(list);
} }

View File

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.cms.constant.CommonConstant; import com.ruoyi.cms.constant.CommonConstant;
import com.ruoyi.cms.domain.JobApply; import com.ruoyi.cms.domain.JobApply;
import com.ruoyi.cms.util.IndustryUtils; import com.ruoyi.cms.util.IndustryUtils;
import com.ruoyi.cms.util.dict.IndustryCacheUtil;
import com.ruoyi.common.core.domain.TreeSelect; import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.Industry; import com.ruoyi.common.core.domain.entity.Industry;
import com.ruoyi.common.core.domain.entity.Industry; import com.ruoyi.common.core.domain.entity.Industry;
@@ -22,6 +23,8 @@ import org.springframework.stereotype.Service;
import com.ruoyi.cms.mapper.IndustryMapper; import com.ruoyi.cms.mapper.IndustryMapper;
import com.ruoyi.cms.service.IIndustryService; import com.ruoyi.cms.service.IIndustryService;
import javax.annotation.PostConstruct;
/** /**
* 行业Service业务层处理 * 行业Service业务层处理
* *
@@ -34,6 +37,13 @@ public class IndustryServiceImpl extends ServiceImpl<IndustryMapper,Industry> im
@Autowired @Autowired
private IndustryMapper industryMapper; private IndustryMapper industryMapper;
// @PostConstruct
// public void initIndustryCache() {
// List<Industry> list = industryMapper.selectIndustryList(new Industry());
// // 推送数据到缓存工具类
// IndustryCacheUtil.refreshCache(list);
// }
/** /**
* 查询行业 * 查询行业
* *

View File

@@ -0,0 +1,85 @@
package com.ruoyi.cms.util.dict;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.domain.entity.Industry;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 行业转换
*/
public class IndustryCacheUtil {
private static final Map<String, Industry> INDUSTRY_ID_MAP = new ConcurrentHashMap<>();
private static final Map<String, Industry> INDUSTRY_REMARK_CODE_MAP = new ConcurrentHashMap<>();
// 国标行业最小有效编码长度
private static final int MIN_CODE_LENGTH = 2;
/**
* 对外统一获取行业名称入口
* @param rawInput 企业传来的industryId可能Long数字 / "H6100"字符串)
*/
public static String getIndustryMatchName(Object rawInput) {
if (rawInput == null) {
return "";
}
String rawCode = StrUtil.trim(rawInput.toString()).toUpperCase();
if (StrUtil.isBlank(rawCode)) {
return "";
}
// ========== 规则1优先尝试【industryId 数字精确匹配】 ==========
Industry industry = INDUSTRY_ID_MAP.get(rawCode);
if (industry != null) {
return industry.getIndustryName();
}
// ========== 规则2数字匹配失败走remark字母编码逻辑 ==========
// 先精确匹配remark编码
industry = INDUSTRY_REMARK_CODE_MAP.get(rawCode);
if (industry != null) {
return industry.getIndustryName();
}
// 判断是否包含字母:只有带字母才向上截断匹配父编码
boolean hasLetter = rawCode.chars().anyMatch(Character::isLetter);
if (!hasLetter) {
// 纯数字,数字库和字母库都找不到,直接返回
return "";
}
// 循环截断后缀向上查找
String tempCode = rawCode;
while (tempCode.length() > MIN_CODE_LENGTH) {
tempCode = tempCode.substring(0, tempCode.length() - 1);
industry = INDUSTRY_REMARK_CODE_MAP.get(tempCode);
if (industry != null) {
return industry.getIndustryName();
}
}
return "";
}
public static void refreshCache(List<Industry> list) {
INDUSTRY_ID_MAP.clear();
INDUSTRY_REMARK_CODE_MAP.clear();
for (Industry item : list) {
if (item.getIndustryId() != null) {
String idKey = item.getIndustryId().toString();
INDUSTRY_ID_MAP.putIfAbsent(idKey, item);
}
if (StrUtil.isNotBlank(item.getRemark())) {
String remarkKey = item.getRemark().toUpperCase();
INDUSTRY_REMARK_CODE_MAP.putIfAbsent(remarkKey, item);
}
}
}
public static void clearCache() {
INDUSTRY_ID_MAP.clear();
INDUSTRY_REMARK_CODE_MAP.clear();
}
}

View File

@@ -133,6 +133,10 @@ public class Company extends BaseEntity
@ApiModelProperty("行业code") @ApiModelProperty("行业code")
private String industryCode; private String industryCode;
@TableField(exist = false)
@ApiModelProperty("行业code")
private String industryName;
/** /**
* 岗位列表 * 岗位列表
*/ */