generated from dxfeng/secondev-chapanda-feishu
简历卡片-原始简历附件OCR识别功能
This commit is contained in:
parent
b343be4cc7
commit
7e5432373b
|
|
@ -5,7 +5,7 @@ import javax.ws.rs.Path;
|
|||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/10/17 10:49 AM
|
||||
* @Description: TODO
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.engine.recruit.exception.CustomizeRunTimeException;
|
|||
import com.engine.recruit.service.ResumeRecognitionService;
|
||||
import com.engine.recruit.util.HttpUtils;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
|
@ -26,7 +26,7 @@ import weaver.formmode.recruit.modeexpand.util.RecruitModeUtil;
|
|||
import weaver.general.BaseBean;
|
||||
import weaver.general.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
|
@ -52,7 +52,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
|
||||
@Override
|
||||
public Map<String, Object> resumeUpload(Map<String, Object> param) {
|
||||
Map<String, Object> returnMap = new HashMap<>();
|
||||
Map<String, Object> returnMap = new HashMap<>(16);
|
||||
returnMap.put("isOcr", true);
|
||||
if (StringUtils.isBlank(OCR_TYPE)) {
|
||||
returnMap.put("isOcr", false);
|
||||
|
|
@ -109,20 +109,115 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
private void alyResumeUpload(int resumeId, Map<String, Object> returnMap) {
|
||||
String response = doAlyPost(resumeId);
|
||||
JSONObject all = JSONObject.parseObject(response);
|
||||
String error_msg = all.getString("error_msg");
|
||||
if (!"成功".equals(error_msg)) {
|
||||
String errorMsg = all.getString("error_msg");
|
||||
if (!"成功".equals(errorMsg)) {
|
||||
throw new CustomizeRunTimeException("阿里云简历识别失败");
|
||||
}
|
||||
Map<String, String> saveResume = new HashMap<>();
|
||||
JSONObject cv_parse = all.getJSONObject("data").getJSONObject("cv_parse");
|
||||
saveResume.putAll(buildBasicInfo(cv_parse.getJSONObject("basic_info")));
|
||||
saveResume.putAll(buildEducations(getJsonArrayFirstIfPresent(cv_parse.getJSONArray("educations"))));
|
||||
saveResume.putAll(buildContact(cv_parse.getJSONObject("contact")));
|
||||
saveResume.putAll(buildJobObjective(cv_parse.getJSONObject("job_objective")));
|
||||
// TODO 阿里云解析内容处理
|
||||
JSONObject parseObject = all.getJSONObject("data").getJSONObject("cv_parse");
|
||||
Map<String, Object> saveResume = parseAlyJsonToMap(parseObject);
|
||||
returnMap.put("data", saveResume);
|
||||
}
|
||||
|
||||
/**
|
||||
* 千里聆解析字段内容处理
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> parseAlyJsonToMap(JSONObject obj) {
|
||||
JSONObject basicInfo = obj.getJSONObject("basic_info");
|
||||
JSONObject contact = obj.getJSONObject("contact");
|
||||
JSONObject jobObjective = obj.getJSONObject("job_objective");
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<>(16);
|
||||
// 姓名
|
||||
String xm = basicInfo.getString("name");
|
||||
dataMap.put("xm", xm);
|
||||
// 电子邮箱
|
||||
String dzyx = contact.getString("email");
|
||||
dataMap.put("dzyx", dzyx);
|
||||
// 手机号码
|
||||
String sjhm = contact.getString("mobile");
|
||||
dataMap.put("sjhm", sjhm);
|
||||
// 年龄
|
||||
String nl = basicInfo.getString("age");
|
||||
dataMap.put("nl", nl);
|
||||
// 出生日期
|
||||
String csrq = basicInfo.getString("birthday");
|
||||
dataMap.put("csrq", parseDateObject(csrq));
|
||||
// 民族
|
||||
String mz = basicInfo.getString("nation");
|
||||
dataMap.put("mz", mz);
|
||||
// 性别
|
||||
String xb = "女".equals(basicInfo.getString("gender")) ? "1" : "0";
|
||||
dataMap.put("xb", xb);
|
||||
// 体重(KG)
|
||||
// 身高(CM)
|
||||
// 籍贯
|
||||
dataMap.put("jg", basicInfo.getString("native_place"));
|
||||
// 婚姻状况
|
||||
// 当前所在地
|
||||
dataMap.put("jzd", basicInfo.getString("extract_location"));
|
||||
// 政治面貌
|
||||
// 在职状态
|
||||
// 工作经验
|
||||
dataMap.put("gzjy", basicInfo.getString("work_years_original"));
|
||||
// 最高学位
|
||||
// 最高学历
|
||||
dataMap.put("zgxl", getBrowserArray(basicInfo.getString("highest_degree"), this::getEducationLevelArray));
|
||||
|
||||
// 毕业院校
|
||||
String byyx = basicInfo.getString("graduate_school");
|
||||
dataMap.put("byyx", byyx);
|
||||
// 期望税前月薪(K)
|
||||
String qwxz = jobObjective.getString("expect_salary_upper");
|
||||
dataMap.put("qwxz", qwxz);
|
||||
// 现税前月薪(K)
|
||||
// 自我评价
|
||||
String zwpj = obj.getString("self_evaluate");
|
||||
dataMap.put("zwpj", zwpj);
|
||||
|
||||
// 明细表数据
|
||||
// 教育经历
|
||||
JSONArray jyjl = obj.getJSONArray("educations");
|
||||
List<Map<String, Object>> studyList = new ArrayList<>();
|
||||
if (null != jyjl && jyjl.size() > 0) {
|
||||
for (int i = 0; i < jyjl.size(); i++) {
|
||||
JSONObject o = (JSONObject) jyjl.get(i);
|
||||
String startTime = o.getString("start_time");
|
||||
String endTime = o.getString("end_time");
|
||||
String studyDate = startTime + "-" + endTime;
|
||||
Map<String, Object> studyMap = new HashMap<>(getDateRange(studyDate, true));
|
||||
studyMap.put("xxmc", o.getString("school"));
|
||||
studyMap.put("xl", getBrowserArray(o.getString("degree"), this::getEducationLevelArray));
|
||||
studyMap.put("zy", o.getString("major"));
|
||||
studyList.add(studyMap);
|
||||
}
|
||||
}
|
||||
dataMap.put("jyjl", studyList);
|
||||
|
||||
// 工作经历
|
||||
JSONArray gzjl = obj.getJSONArray("occupations");
|
||||
List<Map<String, String>> workList = new ArrayList<>();
|
||||
if (null != gzjl && gzjl.size() > 0) {
|
||||
for (int i = 0; i < gzjl.size(); i++) {
|
||||
JSONObject o = (JSONObject) gzjl.get(i);
|
||||
String startTime = o.getString("start_time");
|
||||
String endTime = o.getString("end_time");
|
||||
String workDate = startTime + "-" + endTime;
|
||||
Map<String, String> workMap = new HashMap<>(getDateRange(workDate, false));
|
||||
workMap.put("gsmc", o.getString("company"));
|
||||
workMap.put("gw", o.getString("title"));
|
||||
workMap.put("gzzz", o.getString("desc"));
|
||||
workList.add(workMap);
|
||||
}
|
||||
}
|
||||
|
||||
dataMap.put("gzjl", workList);
|
||||
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 千里聆解析字段内容处理
|
||||
|
|
@ -131,7 +226,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
* @return
|
||||
*/
|
||||
private Map<String, Object> parseQllJsonToMap(JSONObject obj) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
Map<String, Object> dataMap = new HashMap<>(16);
|
||||
// 姓名
|
||||
String xm = parseArray(obj.getJSONArray("姓名"));
|
||||
dataMap.put("xm", xm);
|
||||
|
|
@ -180,6 +275,9 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
// 自我评价
|
||||
String zwpj = parseArray(obj.getJSONArray("个人评价"));
|
||||
dataMap.put("zwpj", zwpj);
|
||||
// 民族
|
||||
dataMap.put("mz", parseArray(obj.getJSONArray("民族")));
|
||||
|
||||
|
||||
// 明细表数据
|
||||
// 教育经历
|
||||
|
|
@ -189,7 +287,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
for (int i = 0; i < jyjl.size(); i++) {
|
||||
JSONObject o = (JSONObject) jyjl.get(i);
|
||||
String studyDate = o.getString("就读时期");
|
||||
Map<String, Object> studyMap = new HashMap<>(getDateRange(studyDate));
|
||||
Map<String, Object> studyMap = new HashMap<>(getDateRange(studyDate, true));
|
||||
studyMap.put("xxmc", o.getString("院校"));
|
||||
studyMap.put("xl", getBrowserArray(o.getString("学历"), this::getEducationLevelArray));
|
||||
studyMap.put("zy", o.getString("专业"));
|
||||
|
|
@ -205,7 +303,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
for (int i = 0; i < gzjl.size(); i++) {
|
||||
JSONObject o = (JSONObject) gzjl.get(i);
|
||||
String workDate = o.getString("工作时间");
|
||||
Map<String, String> workMap = new HashMap<>(getDateRange(workDate));
|
||||
Map<String, String> workMap = new HashMap<>(getDateRange(workDate, false));
|
||||
workMap.put("gsmc", o.getString("工作单位"));
|
||||
workMap.put("gw", o.getString("工作岗位"));
|
||||
workMap.put("gzzz", o.getString("工作内容"));
|
||||
|
|
@ -218,8 +316,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
// 语言能力
|
||||
|
||||
|
||||
// TODO
|
||||
dataMap.put("mz", parseArray(obj.getJSONArray("民族")));
|
||||
// 目前表单暂无字段
|
||||
dataMap.put("wx", parseArray(obj.getJSONArray("微信")));
|
||||
dataMap.put("qq", parseArray(obj.getJSONArray("QQ")));
|
||||
dataMap.put("ah", parseArray(obj.getJSONArray("爱好")));
|
||||
|
|
@ -239,58 +336,6 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
return dataMap;
|
||||
}
|
||||
|
||||
private Map<String, String> buildBasicInfo(JSONObject basicInfo) {
|
||||
Map<String, String> basic = new HashMap<>();
|
||||
if (basicInfo.containsKey("name")) {
|
||||
String jzd;
|
||||
basic.put("xm", Util.null2String(basicInfo.getString("name")));
|
||||
basic.put("nl", Util.null2String(basicInfo.getInteger("age")));
|
||||
if ("男".equals(Util.null2String(basicInfo.getString("gender")))) {
|
||||
basic.put("xb", "0");
|
||||
} else if ("女".equals(Util.null2String(basicInfo.getString("gender")))) {
|
||||
basic.put("xb", "1");
|
||||
}
|
||||
jzd = basicInfo.getJSONObject("location").getString("province") + basicInfo.getJSONObject("location").getString("city");
|
||||
basic.put("jzd", Util.null2String(jzd));
|
||||
}
|
||||
return basic;
|
||||
}
|
||||
|
||||
private Map<String, String> buildEducations(JSONObject educations) {
|
||||
Map<String, String> major = new HashMap<>();
|
||||
if (educations != null) {
|
||||
if (educations.containsKey("major")) {
|
||||
major.put("zy", Util.null2String(educations.getString("major")));
|
||||
}
|
||||
}
|
||||
return major;
|
||||
}
|
||||
|
||||
private Map<String, String> buildContact(JSONObject contact) {
|
||||
Map<String, String> mobile = new HashMap<>();
|
||||
if (contact.containsKey("mobile")) {
|
||||
mobile.put("wx", Util.null2String(contact.getString("mobile")));
|
||||
mobile.put("sjhm", Util.null2String(contact.getString("mobile")));
|
||||
mobile.put("qq", Util.null2String(contact.getString("qq")));
|
||||
mobile.put("email", Util.null2String(contact.getString("email")));
|
||||
}
|
||||
|
||||
return mobile;
|
||||
}
|
||||
|
||||
private Map<String, String> buildJobObjective(JSONObject job_objective) {
|
||||
Map<String, String> expect_salary = new HashMap<>();
|
||||
if (job_objective != null) {
|
||||
if (job_objective.containsKey("expect_salary")) {
|
||||
expect_salary.put("qwxz", Util.null2String(job_objective.getString("expect_salary")));
|
||||
}
|
||||
}
|
||||
return expect_salary;
|
||||
}
|
||||
|
||||
private JSONObject getJsonArrayFirstIfPresent(JSONArray jsonArray) {
|
||||
return jsonArray.size() > 0 ? jsonArray.getJSONObject(0) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resumeId
|
||||
|
|
@ -311,7 +356,6 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
postRequest.addHeader("appId", appId);
|
||||
postRequest.addHeader("timestamp", String.valueOf(currentTime));
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
// TODO 多文件类型兼容
|
||||
String fileName = manager.getImageFileName();
|
||||
builder.addTextBody("type", fileName.substring(fileName.lastIndexOf('.') + 1));
|
||||
builder.addBinaryBody("resume", manager.getInputStream(), ContentType.APPLICATION_OCTET_STREAM, manager.getImageFileName());
|
||||
|
|
@ -334,24 +378,25 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
private String doAlyPost(int resumeId) {
|
||||
try {
|
||||
BaseBean bean = new BaseBean();
|
||||
String PARSE_HOST = bean.getPropValue("youyun", "host");
|
||||
String PATH = bean.getPropValue("youyun", "path");
|
||||
String METHOD = bean.getPropValue("youyun", "method");
|
||||
String APPCODE = bean.getPropValue("youyun", "appcode");
|
||||
String parseHost = bean.getPropValue("youyun", "host");
|
||||
String path = bean.getPropValue("youyun", "path");
|
||||
String method = bean.getPropValue("youyun", "method");
|
||||
String appcode = bean.getPropValue("youyun", "appcode");
|
||||
ImageFileManager manager = new ImageFileManager();
|
||||
manager.getImageFileInfoById(resumeId);
|
||||
String filePath = manager.getFileRealPath();
|
||||
File file = new File(filePath);
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "APPCODE " + APPCODE);
|
||||
Map<String, String> headers = new HashMap<>(2);
|
||||
headers.put("Authorization", "APPCODE " + appcode);
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> queryMap = new HashMap<>();
|
||||
Map<String, String> bodyMap = new HashMap<>();
|
||||
byte[] bytes = FileUtils.readFileToByteArray(file);
|
||||
Map<String, String> queryMap = new HashMap<>(1);
|
||||
Map<String, String> bodyMap = new HashMap<>(2);
|
||||
InputStream inputStream = manager.getInputStream();
|
||||
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||
String base64 = Base64.encodeBase64String(bytes);
|
||||
bodyMap.put("content", base64);
|
||||
bodyMap.put("ext", "doc");
|
||||
HttpResponse response = HttpUtils.doPost(PARSE_HOST, PATH, METHOD, headers, queryMap, bodyMap);
|
||||
String fileName = manager.getImageFileName();
|
||||
String suffixType = fileName.substring(fileName.lastIndexOf('.') + 1);
|
||||
bodyMap.put("ext", suffixType);
|
||||
HttpResponse response = HttpUtils.doPost(parseHost, path, method, headers, queryMap, bodyMap);
|
||||
return EntityUtils.toString(response.getEntity());
|
||||
} catch (Exception var10) {
|
||||
throw new ECException("简历解析失败!详情:" + var10.getMessage());
|
||||
|
|
@ -432,12 +477,27 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
* @param date
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String> getDateRange(String date) {
|
||||
private Map<String, String> getDateRange(String date, boolean isStudy) {
|
||||
Map<String, String> dataRangeMap = new HashMap<>(2);
|
||||
String[] split = date.split("-");
|
||||
if (split.length == 2) {
|
||||
String start = getFormatDate(split[0]);
|
||||
String end = getFormatDate(split[1]);
|
||||
if (start.length() == 4) {
|
||||
if (isStudy) {
|
||||
start += "-09-01";
|
||||
} else {
|
||||
start = "";
|
||||
}
|
||||
}
|
||||
if (end.length() == 4) {
|
||||
if (isStudy) {
|
||||
end += "-07-01";
|
||||
} else {
|
||||
end = "";
|
||||
}
|
||||
}
|
||||
|
||||
dataRangeMap.put("kssj", start);
|
||||
dataRangeMap.put("jssj", end);
|
||||
}
|
||||
|
|
@ -451,11 +511,13 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
* @return
|
||||
*/
|
||||
private String getFormatDate(String dateStr) {
|
||||
dateStr = dateStr.replace(".", "-");
|
||||
dateStr = dateStr.replace(".", "-").replace("\\/", "-");
|
||||
if (dateStr.length() == 7) {
|
||||
return dateStr + "-01";
|
||||
} else if (dateStr.length() == 10) {
|
||||
return dateStr;
|
||||
} else if (dateStr.length() == 4) {
|
||||
return dateStr;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
@ -467,7 +529,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
* @return
|
||||
*/
|
||||
private Map<String, String> getDegreeArray(String text) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, String> map = new HashMap<>(2);
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
String id = ModeBrowserCommonInfo.getDegreeId(text);
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
|
|
@ -505,7 +567,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog
|
|||
* @return
|
||||
*/
|
||||
private Map<String, String> getEducationLevelArray(String text) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, String> map = new HashMap<>(2);
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
String id = ModeBrowserCommonInfo.getEducationLevelId(text);
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue