1.读取execl职位
package com.beagledata.mgc.lucas.jdcvmatch.openapi.utils;
import com.beagledata.mgc.lucas.jdcvmatch.common.domain.JD;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
/**
- Created by mahongfei on 2019/9/17.
/
public class ExeclUtils {
/*-
读取本地excel jd文件
*/
public static List readJdExcel(File excelFile, List list) {
try {
String filePath = excelFile.getAbsolutePath();
InputStream input = new FileInputStream(excelFile);
boolean isE2007 = false;
//判断是否是excel2007格式
if (filePath.endsWith(“xlsx”)) {
isE2007 = true;
}Workbook wb; //根据文件格式(2003或者2007)来初始化 if (isE2007) { wb = new XSSFWorkbook(input); } else { wb = new HSSFWorkbook(input); } Iterator<Sheet> sheetIterator = wb.sheetIterator(); int sheetIndex = 0; while (sheetIterator.hasNext()) { Sheet sheet = sheetIterator.next(); int rowCount = sheet.getLastRowNum() + 1; if (filePath.contains("JAVA岗统计表")) { if (filePath.endsWith(".xlsx") && sheetIndex == 1) { //一列一个元素, 从上到下每行表示: ID, 职位名, 搜寻方向, 岗位职责, 任职要求, 导出简历数 Row idRow = sheet.getRow(0); Row nameRow = sheet.getRow(1); Row derectionRow = sheet.getRow(2); Row dutyRow = sheet.getRow(3); Row requireRow = sheet.getRow(4); int cellNum = idRow.getLastCellNum(); for (int i = 1; i < cellNum; i++) { String jdId = String.valueOf(idRow.getCell(i)); if (StringUtils.isEmpty(jdId) || jdId.equals("null")) { continue; } JD jd = new JD(); jd.setJdId(jdId); jd.setName(String.valueOf(nameRow.getCell(i))); jd.setDirection(String.valueOf(derectionRow.getCell(i))); jd.setJobDuty(String.valueOf(dutyRow.getCell(i))); jd.setJobRequirement(String.valueOf(requireRow.getCell(i))); list.add(jd); } } else { for (int i = 1; i < rowCount; i++) { //跳过表头 ID, 职位名, 搜寻方向, 岗位职责, 任职要求, 导出简历数 Row row = sheet.getRow(i); String jdId = String.valueOf(row.getCell(0)); if (StringUtils.isEmpty(jdId) || jdId.equals("null")) { continue; }
-
// 根据类添加参数到jd(row.getCell(0))
JD jd = new JD();
jd.setJdId(jdId);
jd.setName(DataUtils.parseString(String.valueOf(row.getCell(1))));
jd.setDirection(DataUtils.parseString(String.valueOf(row.getCell(2))));
jd.setJobDuty(DataUtils.parseString(String.valueOf(row.getCell(3))));
jd.setJobRequirement(DataUtils.parseString(String.valueOf(row.getCell(4))));
list.add(jd);
}
}
} else {
for (int i = 1; i < rowCount; i++) { //跳过表头 ID, 职位名, 搜寻方向, 岗位职责, 任职要求, 导出简历数
Row row = sheet.getRow(i);
String jdId = String.valueOf(row.getCell(0));
if (StringUtils.isEmpty(jdId) || jdId.equals(“null”)) {
continue;
}
// 根据类添加参数到jd(row.getCell(0))
JD jd = new JD();
jd.setJdId(jdId);
jd.setName(DataUtils.parseString(String.valueOf(row.getCell(1))));
jd.setDirection(DataUtils.parseString(String.valueOf(row.getCell(2))));
jd.setJobDuty(DataUtils.parseString(String.valueOf(row.getCell(3))));
jd.setJobRequirement(DataUtils.parseString(String.valueOf(row.getCell(4))));
list.add(jd);
}
}
sheetIndex++;
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Excel解析的 JD 数量: " + list.size());
return list;
}
}
2.读取word职位
package com.beagledata.mgc.lucas.jdcvmatch.openapi.utils;
import com.beagledata.mgc.lucas.jdcvmatch.common.domain.JD;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.util.StringUtils;
import java.io.*;
import java.util.Date;
/**
-
Created by mahongfei on 2019/9/17.
/
public class WordUtils {
/*-
解析jd doc文件
*/
public static JD docJdParse(String fileName, String filePath) {
File doc = new File(filePath);
if (!doc.exists() || !filePath.endsWith(“doc”)) {
System.out.println(“文件不存在或者文件不是doc结尾”);
}try {
InputStream is = new FileInputStream(doc);
WordExtractor we = new WordExtractor(is);
return parseJdContent(fileName, we.getText());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
- 解析jd docx文件
*/
public static JD docxJdParse(String fileName, String filePath) {
if (StringUtils.isEmpty(filePath) || !filePath.endsWith(“docx”)) {
System.out.println(“文件不存在或者文件不是docx结尾”);
}
try {
InputStream is = new FileInputStream(filePath);
XWPFDocument doc = new XWPFDocument(is);
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
return parseJdContent(fileName, extractor.getText());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
- 根据jd text 创建jd对象
*/
private static JD parseJdContent(String fileName, String str) {
String duty = “”;
String require = “”;
String duryFlag = “岗位职责”;
if (str.contains(“工作职责”)) {
duryFlag = “工作职责”;
}
if (str.contains(“职责描述”)) {
duryFlag = “职责描述”;
}
if (str.contains(“岗位描述”)) {
duryFlag = “岗位描述”;
}
if (str.contains(“岗位职能”)) {
duryFlag = “岗位职能”;
}
String requireFlag = “任职要求”;
if (str.contains(“任职资格”)) {
requireFlag = “任职资格”;
}
if (str.contains(“职位要求”)) {
requireFlag = “职位要求”;
}
int dfIndex = str.indexOf(duryFlag);
int rfIndex = str.indexOf(requireFlag);
if (dfIndex < 0 || rfIndex < 0) {
System.out.println(“没有找到啊”);
return null;
}
duty = str.substring(dfIndex + 5, rfIndex);
require = str.substring(rfIndex + 5);
fileName = fileName.replace(“JD”, “”).replace("-", “”);
JD jd = new JD();
String jdId = IdUtils.generateShortUuid();
jd.setJdId(jdId);
if (fileName.contains(".doc")) {
fileName = fileName.substring(0, fileName.indexOf(".doc"));
}
jd.setName(DataUtils.parseString(fileName));
jd.setCreateTime(new Date());
jd.setJobDuty(DataUtils.parseString(duty));
jd.setJobRequirement(DataUtils.parseString(require));
return jd;
}
}
3.创建随机id
package com.beagledata.mgc.lucas.jdcvmatch.openapi.utils;
-
import org.springframework.util.StringUtils;
import java.util.UUID;
/**
-
Created by Cyf on 2019/9/18
**/
public class IdUtils {
private static final String HELPERSPACE = " ";
private static final String[] chars = new String[] { “a”, “b”, “c”, “d”, “e”, “f”,
“g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”,
“t”, “u”, “v”, “w”, “x”, “y”, “z”, “0”, “1”, “2”, “3”, “4”, “5”,
“6”, “7”, “8”, “9”, “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”,
“J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”,
“W”, “X”, “Y”, “Z” };public static String generateShortUuid() {
StringBuffer shortBuffer = new StringBuffer();
String uuid = UUID.randomUUID().toString().replace("-", “”);
for (int i = 0; i < 8; i++) {
String str = uuid.substring(i * 4, i * 4 + 4);
int x = Integer.parseInt(str, 16);
shortBuffer.append(chars[x % 0x3E]);
}
return shortBuffer.toString();}
/**
- 根据空格分割字符串,返回每个单词首字母拼接的字符串
*/
public static String getFirstCharBySpace(String str) {
if(StringUtils.isEmpty(str)) return str;
StringBuilder result = new StringBuilder();
String[] words = str.split(HELPERSPACE);
for(String word : words) {
if(StringUtils.isEmpty(word)) continue;
result.append(word.charAt(0));
}
return result.toString();
}
}
- 根据空格分割字符串,返回每个单词首字母拼接的字符串
4.数据处理类
package com.beagledata.mgc.lucas.jdcvmatch.openapi.utils;
import com.alibaba.fastjson.JSONObject;
import com.beagledata.mgc.lucas.jdcvmatch.common.domain.JD;
import org.springframework.util.StringUtils;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
-
Created by Cyf on 2019/9/17
/
public class DataUtils {
/- 读取本地word jd文件
*/
public static List readJdWord(File wordFile, List list) {
String filePath = wordFile.getAbsolutePath();
JD jd;
if (filePath.endsWith(“docx”)) {
jd = WordUtils.docxJdParse(wordFile.getName(), filePath);
} else if (filePath.endsWith(“doc”)) {
jd = WordUtils.docJdParse(wordFile.getName(), filePath);
} else {
System.out.println(“readJdWord, 文件不是doc 或 docx”);
jd = null;
}
if (jd != null) {
list.add(jd);
} else {
System.out.println(String.format(“文件 [%s] 解析失败”, wordFile.getName()));
}
return list;
}
/**
- 替换特殊字符及空格
*/
public static String parseString(String value) {
if (!StringUtils.isEmpty(value)) {
return value.replaceAll("@", “”).replaceAll("#", “”).replaceAll("\b", “”).replaceAll("\n", “”).replaceAll("\r", “”).replaceAll(" ", “”);
}
return value;
}
/**
- 处理cv参数
*/
public static JSONObject parseCvParams(Map<String, Object> map, JSONObject jsonObject) {
for (String key : map.keySet()) {
if (key.equals(“gender_id”)) {
if (String.valueOf(map.get(key)).contains(“男”)) {
jsonObject.put(“gender_id”, “1”);
} else if (String.valueOf(map.get(key)).contains(“女”)) {
jsonObject.put(“gender_id”, “2”);
} else {
jsonObject.put(“gender_id”, “0”);
}
} else if (key.equals(“is_married”)) {
if (String.valueOf(map.get(key)) != null && String.valueOf(map.get(key)).contains(“已婚”)) {
jsonObject.put(“is_married”, “1”);
} else {
jsonObject.put(“is_married”, “0”);
}
} else if (key.equals(“birth”)) {
String year = String.valueOf(map.get(key)).substring(0, String.valueOf(map.get(key)).indexOf(“年”));
jsonObject.put(“birth_year”, DataUtils.parseString(year));
String month = “”;
if (!String.valueOf(map.get(key)).contains(“月”)) {
month = “1”;
} else {
month = String.valueOf(map.get(key)).substring(String.valueOf(map.get(key)).indexOf(“年”) + 1, String.valueOf(map.get(key)).indexOf(“月”));
}
jsonObject.put(“birth_month”, DataUtils.parseString(month));
String day = “”;
if (!String.valueOf(map.get(key)).contains(“日”)) {
day = “1”;
} else {
day = String.valueOf(map.get(key)).substring(String.valueOf(map.get(key)).indexOf(“月”) + 1, String.valueOf(map.get(key)).indexOf(“日”));
}
jsonObject.put(“birth_day”, DataUtils.parseString(day));
} else if (key.equals(“name”)) {
jsonObject.put(“name”, map.get(key));
} else if (key.equals(“address”)) {
jsonObject.put(“address”, map.get(key));
} else if (key.equals(“id”)) {
jsonObject.put(“id”, IdUtils.generateShortUuid());
} else if (key.equals(“education_experience”)) {
jsonObject.put(“education_experience”, map.get(key));
} else if (key.equals(“work_experience”)) {
jsonObject.put(“work_experience”, map.get(key));
} else if (key.equals(“project_experience”)) {
jsonObject.put(“project_experience”, map.get(key));
} else if (key.equals(“salary_total”)) {
jsonObject.put(“salary_total”, map.get(key));
} else if (key.equals(“description”)) {
jsonObject.put(“description”, map.get(key));
} else if (key.equals(“school”)) {
jsonObject.put(“school”, map.get(key));
} else if (key.equals(“major”)) {
jsonObject.put(“major”, map.get(key));
} else if (key.equals(“company_name”)) {
jsonObject.put(“company_name”, map.get(key));
} else if (key.equals(“job”)) {
jsonObject.put(“job”, map.get(key));
} else if (key.equals(“duty”)) {
jsonObject.put(“duty”, map.get(key));
} else if (key.equals(“projectName”)) {
jsonObject.put(“name”, map.get(key));
} else if (key.equals(“projectDescription”)) {
jsonObject.put(“description”, map.get(key));
} else if (key.equals(“education_id”)) {
if (“博士”.equals(map.get(key))) {
jsonObject.put(“education_id”, “1”);
} else if (“MBA”.equals(map.get(key)) || “EMBA”.equals(map.get(key))) {
jsonObject.put(“education_id”, “2”);
} else if (“硕士”.equals(map.get(key))) {
jsonObject.put(“education_id”, “3”);
} else if (“本科”.equals(map.get(key))) {
jsonObject.put(“education_id”, “4”);
} else if (“大专”.equals(map.get(key)) || “专科”.equals(map.get(key))) {
jsonObject.put(“education_id”, “5”);
} else if (“高中”.equals(map.get(key)) || “中专”.equals(map.get(key))) {
jsonObject.put(“education_id”, “6”);
}
}
}
return jsonObject;
}
}
- 读取本地word jd文件