diff --git a/src/com/engine/recruit/conn/ApplicantCommonInfo.java b/src/com/engine/recruit/conn/ApplicantCommonInfo.java index 319e930..f0aa25a 100644 --- a/src/com/engine/recruit/conn/ApplicantCommonInfo.java +++ b/src/com/engine/recruit/conn/ApplicantCommonInfo.java @@ -238,4 +238,19 @@ public class ApplicantCommonInfo { } return null; } + + /** + * 获取ImageField + * + * @param docId + * @return + */ + public static int getImageFieldByDocId(String docId) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select imagefileid from docimagefile where docid = ? ", docId); + if (rs.next()) { + return rs.getInt("imagefileid"); + } + return -1; + } } diff --git a/src/com/engine/recruit/conn/ModeBrowserCommonInfo.java b/src/com/engine/recruit/conn/ModeBrowserCommonInfo.java index 505eba9..7cb0cc7 100644 --- a/src/com/engine/recruit/conn/ModeBrowserCommonInfo.java +++ b/src/com/engine/recruit/conn/ModeBrowserCommonInfo.java @@ -22,7 +22,7 @@ public class ModeBrowserCommonInfo { } /** - * 根据名称,获取简历来源ID + * 根据名称,获取工作经验ID * * @param name * @return @@ -31,6 +31,23 @@ public class ModeBrowserCommonInfo { return getBrowserId("10", name); } + + /** + * 获取学位ID + * + * @param name + * @return + */ + public static String getDegreeId(String name) { + return getBrowserId("12", name); + } + + /** + * 获取学历ID + * + * @param name + * @return + */ public static String getEducationLevelId(String name) { if (StringUtils.isBlank(name)) { return null; diff --git a/src/com/engine/recruit/enums/HighestDegreeEnum.java b/src/com/engine/recruit/enums/HighestDegreeEnum.java index c49e8e9..fe6fe4b 100644 --- a/src/com/engine/recruit/enums/HighestDegreeEnum.java +++ b/src/com/engine/recruit/enums/HighestDegreeEnum.java @@ -13,16 +13,16 @@ public enum HighestDegreeEnum { */ OTHER(1, "其他"), JUNIOR_MIDDLE_SCHOOL(2, "初中"), - HIGH_SCHOOL(2, "高中"), - SECONDARY_TECHNOLOGY(2, "中技"), - SECONDARY_SPECIALIZED_SCHOOL(2, "中专"), - JUNIOR_COLLEGE(2, "大专"), - UNDERGRADUATE(2, "本科"), - MASTER_DEGREE(2, "硕士研究生"), - DOCTORAL_STUDENTS(2, "博士研究生"), - MBA(2, "MBA"), - EMBA(2, "EMBA"), - POST_DOCTORAL(2, "博士后"); + HIGH_SCHOOL(3, "高中"), + SECONDARY_TECHNOLOGY(4, "中技"), + SECONDARY_SPECIALIZED_SCHOOL(5, "中专"), + JUNIOR_COLLEGE(6, "大专"), + UNDERGRADUATE(7, "本科"), + MASTER_DEGREE(8, "硕士研究生"), + DOCTORAL_STUDENTS(9, "博士研究生"), + MBA(10, "MBA"), + EMBA(11, "EMBA"), + POST_DOCTORAL(12, "博士后"); HighestDegreeEnum(Integer id, String name) { this.id = id; diff --git a/src/com/engine/recruit/service/impl/ResumeRecognitionServiceImpl.java b/src/com/engine/recruit/service/impl/ResumeRecognitionServiceImpl.java index e09d0a4..9815290 100644 --- a/src/com/engine/recruit/service/impl/ResumeRecognitionServiceImpl.java +++ b/src/com/engine/recruit/service/impl/ResumeRecognitionServiceImpl.java @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.engine.core.exception.ECException; import com.engine.core.impl.Service; +import com.engine.recruit.conn.ApplicantCommonInfo; +import com.engine.recruit.conn.ModeBrowserCommonInfo; import com.engine.recruit.exception.CustomizeRunTimeException; import com.engine.recruit.service.ResumeRecognitionService; import com.engine.resumestorage.util.HttpUtils; @@ -31,8 +33,11 @@ import java.security.NoSuchAlgorithmException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.function.Function; /** * @author:dxfeng @@ -54,17 +59,18 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog return returnMap; } String resumeId = Util.null2String(param.get("resumeId")); - if (StringUtils.isBlank(resumeId)) { - throw new CustomizeRunTimeException("原始简历文件获取失败"); + int imageField = ApplicantCommonInfo.getImageFieldByDocId(resumeId); + if (-1 == imageField) { + throw new CustomizeRunTimeException("原始简历文件获取失败,请重新上传原始简历"); } // 调用千里聆服务 if ("1".equals(OCR_TYPE)) { - qllResumeUpload(Integer.parseInt(resumeId), returnMap); + qllResumeUpload(imageField, returnMap); } // 调用阿里云服务 if ("2".equals(OCR_TYPE)) { - alyResumeUpload(Integer.parseInt(resumeId), returnMap); + alyResumeUpload(imageField, returnMap); } return returnMap; @@ -110,35 +116,41 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog Map saveResume = new HashMap<>(); JSONObject cv_parse = all.getJSONObject("data").getJSONObject("cv_parse"); saveResume.putAll(buildBasicInfo(cv_parse.getJSONObject("basic_info"))); - saveResume.putAll(buildEducations(this.getJsonArrayFirstIfPresent(cv_parse.getJSONArray("educations")))); + saveResume.putAll(buildEducations(getJsonArrayFirstIfPresent(cv_parse.getJSONArray("educations")))); saveResume.putAll(buildContact(cv_parse.getJSONObject("contact"))); saveResume.putAll(buildJobObjective(cv_parse.getJSONObject("job_objective"))); - saveResume.putAll(buildOccupations(this.getJsonArrayFirstIfPresent(cv_parse.getJSONArray("occupations")))); + // TODO 阿里云解析内容处理 returnMap.put("data", saveResume); } + /** + * 千里聆解析字段内容处理 + * + * @param obj + * @return + */ private Map parseQllJsonToMap(JSONObject obj) { Map dataMap = new HashMap<>(); // 姓名 String xm = parseArray(obj.getJSONArray("姓名")); - dataMap.put("xm", parseInputObject(xm)); + dataMap.put("xm", xm); // 电子邮箱 String dzyx = parseArray(obj.getJSONArray("电子邮箱")); - dataMap.put("dzyx", parseInputObject(dzyx)); + dataMap.put("dzyx", dzyx); // 手机号码 String sjhm = parseArray(obj.getJSONArray("手机号")); - dataMap.put("sjhm", parseInputObject(sjhm)); + dataMap.put("sjhm", sjhm); // 年龄 String nl = parseArray(obj.getJSONArray("年龄")); - dataMap.put("nl", parseInputObject(nl)); + dataMap.put("nl", nl); // 出生日期 String csrq = parseArray(obj.getJSONArray("出生日期")); dataMap.put("csrq", parseDateObject(csrq)); // 民族 // 性别 String xb = "男".equals(parseArray(obj.getJSONArray("性别"))) ? "0" : "1"; - dataMap.put("xb", parseValueObject(xb)); + dataMap.put("xb", xb); // 体重(KG) // 身高(CM) // 籍贯 @@ -151,32 +163,60 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog // 工作经验 dataMap.put("gzjy", parseArray(obj.getJSONArray("工作经验"))); // 最高学位 - dataMap.put("zgxw", parseArray(obj.getJSONArray("最高学位"))); + dataMap.put("zgxw", getBrowserArray(parseArray(obj.getJSONArray("最高学位")), this::getDegreeArray)); // 最高学历 - dataMap.put("zgxlwb", parseArray(obj.getJSONArray("最高学历"))); + dataMap.put("zgxl", getBrowserArray(parseArray(obj.getJSONArray("最高学历")), this::getEducationLevelArray)); + // 专业 String zy = parseArray(obj.getJSONArray("专业")); - dataMap.put("zy", parseInputObject(zy)); + dataMap.put("zy", zy); // 毕业院校 String byyx = parseArray(obj.getJSONArray("毕业院校")); - dataMap.put("byyx", parseInputObject(byyx)); + dataMap.put("byyx", byyx); // 期望税前月薪(K) String qwxz = parseArray(obj.getJSONArray("期望薪资")); - dataMap.put("qwxz", parseInputObject(qwxz)); + dataMap.put("qwxz", qwxz); // 现税前月薪(K) // 自我评价 String zwpj = parseArray(obj.getJSONArray("个人评价")); - dataMap.put("zwpj", parseInputObject(zwpj)); + dataMap.put("zwpj", zwpj); // 明细表数据 // 教育经历 + JSONArray jyjl = obj.getJSONArray("学业信息"); + List> studyList = new ArrayList<>(); + if (null != jyjl && jyjl.size() > 0) { + for (int i = 0; i < jyjl.size(); i++) { + JSONObject o = (JSONObject) jyjl.get(i); + String studyDate = o.getString("就读时期"); + Map studyMap = new HashMap<>(getDateRange(studyDate)); + studyMap.put("xxmc", o.getString("院校")); + studyMap.put("xl", getBrowserArray(o.getString("学历"), this::getEducationLevelArray)); + studyMap.put("zy", o.getString("专业")); + studyList.add(studyMap); + } + } + dataMap.put("jyjl", studyList); + // 工作经历 + JSONArray gzjl = obj.getJSONArray("工作信息"); + List> workList = new ArrayList<>(); + if (null != gzjl && gzjl.size() > 0) { + for (int i = 0; i < gzjl.size(); i++) { + JSONObject o = (JSONObject) gzjl.get(i); + String workDate = o.getString("工作时间"); + Map workMap = new HashMap<>(getDateRange(workDate)); + workMap.put("gsmc", o.getString("工作单位")); + workMap.put("gw", o.getString("工作岗位")); + workMap.put("gzzz", o.getString("工作内容")); + workList.add(workMap); + } + } + + dataMap.put("gzjl", workList); // 项目经验 // 语言能力 - // TODO - // 当前所在地 - // TODO dataMap.put("mz", parseArray(obj.getJSONArray("民族"))); @@ -191,18 +231,16 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog dataMap.put("yysp", parseArray(obj.getJSONArray("英语水平"))); dataMap.put("jnzs", parseArray(obj.getJSONArray("技能证书"))); dataMap.put("xyjl", parseArray(obj.getJSONArray("校园经历"))); - dataMap.put("gzxg", parseArray(obj.getJSONArray("工作信息"))); dataMap.put("qwcsgw", parseArray(obj.getJSONArray("期望从事岗位"))); dataMap.put("qwgzdd", parseArray(obj.getJSONArray("期望工作地点"))); dataMap.put("xmjl", parseArray(obj.getJSONArray("项目经历"))); - dataMap.put("xyxg", parseArray(obj.getJSONArray("学业信息"))); return dataMap; } private Map buildBasicInfo(JSONObject basicInfo) { - Map basic = new HashMap(); + Map basic = new HashMap<>(); if (basicInfo.containsKey("name")) { String jzd; basic.put("xm", Util.null2String(basicInfo.getString("name"))); @@ -215,7 +253,6 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog jzd = basicInfo.getJSONObject("location").getString("province") + basicInfo.getJSONObject("location").getString("city"); basic.put("jzd", Util.null2String(jzd)); } - return basic; } @@ -223,28 +260,26 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog Map major = new HashMap<>(); if (educations != null) { if (educations.containsKey("major")) { - major.put("sxzy", Util.null2String(educations.getString("major"))); + major.put("zy", Util.null2String(educations.getString("major"))); } - } return major; } private Map buildContact(JSONObject contact) { - Map mobile = new HashMap(); + Map 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 buildJobObjective(JSONObject job_objective) { - Map expect_salary = new HashMap(); + Map 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"))); @@ -253,17 +288,6 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog return expect_salary; } - private Map buildOccupations(JSONObject occupations) { - Map company = new HashMap(); - if (occupations != null) { - if (occupations.containsKey("company")) { - company.put("gs", Util.null2String(occupations.getString("expect_salary"))); - } - - } - return company; - } - private JSONObject getJsonArrayFirstIfPresent(JSONArray jsonArray) { return jsonArray.size() > 0 ? jsonArray.getJSONObject(0) : null; } @@ -287,8 +311,9 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog postRequest.addHeader("appId", appId); postRequest.addHeader("timestamp", String.valueOf(currentTime)); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - // TODO - builder.addTextBody("type", "pdf"); + // TODO 多文件类型兼容 + String fileName = manager.getImageFileName(); + builder.addTextBody("type", fileName.substring(fileName.lastIndexOf('.') + 1)); builder.addBinaryBody("resume", manager.getInputStream(), ContentType.APPLICATION_OCTET_STREAM, manager.getImageFileName()); HttpEntity entity = builder.build(); postRequest.setEntity(entity); @@ -298,7 +323,7 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog HttpEntity responseEntity = response.getEntity(); return EntityUtils.toString(responseEntity); } catch (Exception e) { - throw new RuntimeException(e); + throw new CustomizeRunTimeException(e); } } @@ -384,23 +409,6 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog } - /** - * 转换文本对象 - * - * @param value - * @return - */ - private String parseInputObject(String value) { - return value; - // return "{value: \"" + value + "\",showhtml: \"" + value + "\"}"; - } - - - private String parseValueObject(String value) { - return value; - // return "{value: \"" + value + "\"}"; - } - /** * 转换日期对象 * @@ -415,6 +423,98 @@ public class ResumeRecognitionServiceImpl extends Service implements ResumeRecog } catch (ParseException e) { value = ""; } - return parseInputObject(value); + return value; } + + /** + * 获取开始时间和结束时间 + * + * @param date + * @return + */ + private Map getDateRange(String date) { + Map dataRangeMap = new HashMap<>(2); + String[] split = date.split("-"); + if (split.length == 2) { + String start = getFormatDate(split[0]); + String end = getFormatDate(split[1]); + dataRangeMap.put("kssj", start); + dataRangeMap.put("jssj", end); + } + return dataRangeMap; + } + + /** + * 获取yyyy-MM-dd时间格式日期 + * + * @param dateStr + * @return + */ + private String getFormatDate(String dateStr) { + dateStr = dateStr.replace(".", "-"); + if (dateStr.length() == 7) { + return dateStr + "-01"; + } else if (dateStr.length() == 10) { + return dateStr; + } + return ""; + } + + /** + * 构建学位字段信息 + * + * @param text + * @return + */ + private Map getDegreeArray(String text) { + Map map = new HashMap<>(); + if (StringUtils.isNotBlank(text)) { + String id = ModeBrowserCommonInfo.getDegreeId(text); + if (StringUtils.isNotBlank(id)) { + map.put("id", id); + map.put("name", text); + } + } + return map; + } + + /** + * 构建浏览按钮字段信息格式 + * + * @param text + * @param fun + * @return + */ + private List> getBrowserArray(String text, Function> fun) { + List> list = new ArrayList<>(); + if (StringUtils.isNotBlank(text)) { + String[] split = text.split(","); + for (String s : split) { + Map apply = fun.apply(s); + list.add(apply); + } + } + + return list; + } + + /** + * 构建学历字段信息 + * + * @param text + * @return + */ + private Map getEducationLevelArray(String text) { + Map map = new HashMap<>(); + if (StringUtils.isNotBlank(text)) { + String id = ModeBrowserCommonInfo.getEducationLevelId(text); + if (StringUtils.isNotBlank(id)) { + map.put("id", id); + map.put("name", text); + } + } + return map; + } + + }