Commit 9d942a37 by 284718418@qq.com

百度简历解析TIC

parent 3b46bc9e
...@@ -22,13 +22,18 @@ import cn.timer.api.dao.kqmk.KqglAssoKqzdkfsMapper; ...@@ -22,13 +22,18 @@ import cn.timer.api.dao.kqmk.KqglAssoKqzdkfsMapper;
import cn.timer.api.dao.qyzx.QyzxEmpLoginMapper; import cn.timer.api.dao.qyzx.QyzxEmpLoginMapper;
import cn.timer.api.dao.yggl.YgglMainEmpMapper; import cn.timer.api.dao.yggl.YgglMainEmpMapper;
import cn.timer.api.dao.zpgl.ZpglRcxxMapper; import cn.timer.api.dao.zpgl.ZpglRcxxMapper;
import cn.timer.api.dto.baidu.BaiduTicResumeDto;
import cn.timer.api.dto.baidu.BasicInfos;
import cn.timer.api.dto.zpgl.ZpglRcxxDto; import cn.timer.api.dto.zpgl.ZpglRcxxDto;
import cn.timer.api.dto.zpgl.ZpglRcxxEntryDto; import cn.timer.api.dto.zpgl.ZpglRcxxEntryDto;
import cn.timer.api.utils.Md5; import cn.timer.api.utils.Md5;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import cn.timer.api.utils.baidu.BaiduTicUtil;
import cn.timer.api.utils.baidu.Base64;
import cn.timer.api.utils.query.BaseQuery; import cn.timer.api.utils.query.BaseQuery;
import cn.timer.api.config.enuminterface.YgEnumInterface.jobStatus; import cn.timer.api.config.enuminterface.YgEnumInterface.jobStatus;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
...@@ -51,7 +56,10 @@ import org.springframework.util.StringUtils; ...@@ -51,7 +56,10 @@ import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -74,6 +82,9 @@ import java.util.Map; ...@@ -74,6 +82,9 @@ import java.util.Map;
@Slf4j @Slf4j
public class ZpglController { public class ZpglController {
@Autowired
private BaiduTicUtil baiduTicUtil;
@Value(value = "${config-8timer.init-password}") @Value(value = "${config-8timer.init-password}")
private String pwd; private String pwd;
// 回调地址 // 回调地址
...@@ -417,6 +428,40 @@ public class ZpglController { ...@@ -417,6 +428,40 @@ public class ZpglController {
} }
/** /**
* 招聘-导入候选人简历
* @param userBean
* @param file
* @param request
* @return
*/
@ResponseBody
@PostMapping("/resume_import_candidate")
@ApiOperation(value = "招聘-导入候选人简历", httpMethod = "POST", notes = "招聘-导入候选人简历")
public Result<Object> resumeImportCandidate(@CurrentUser UserBean userBean, @RequestParam(required = true) MultipartFile file,
HttpServletRequest request) {
try {
BaiduTicResumeDto baiduTicResumeDto = BaiduTicResumeDto.builder().filename("邓志鸿.docx").filetype("docx").filedata(Base64.getStrFromPath(file)).build();
ResponseEntity<String> resumeString = baiduTicUtil.getResumeByCvParser(baiduTicResumeDto);
log.info("resumeString:{}",resumeString.getBody());
JSONObject json = (JSONObject) JSONObject.parse(resumeString.getBody());
if("success".equals(json.get("error_msg"))){
BasicInfos asicInfos = JSONObject.toJavaObject(JSONObject.parse(json.get("results").toString()), BasicInfos.class);
}else {
return ResultUtil.error("操作失败");
}
return ResultUtil.success("操作成功");
// return ZpglRcxx.builder().build().updateById()?ResultUtil.success("操作成功"):ResultUtil.error("操作失败");
} catch (Exception e) {
e.printStackTrace();
throw new CustomException("招聘-导入候选人简历失败");
}
}
/**
* 获取统计数据 * 获取统计数据
* @param queryWrapper * @param queryWrapper
* @param status * @param status
......
package cn.timer.api.dto.baidu;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BasicInfos implements Serializable {
}
package cn.timer.api.dto.baidu;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EducationInfos implements Serializable {
}
package cn.timer.api.dto.baidu;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProjectInfos implements Serializable {
}
package cn.timer.api.dto.baidu;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResumeExtract implements Serializable {
}
package cn.timer.api.dto.baidu;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022/3/30
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WorkInfos implements Serializable {
}
...@@ -26,15 +26,15 @@ import java.util.Map; ...@@ -26,15 +26,15 @@ import java.util.Map;
public class BaiduTicUtil { public class BaiduTicUtil {
@Value("${config-8timer.baidu-tic.appid}") @Value("${config-8timer.baidu-tic.appid}")
private static String appid = "XOATkGqX6LvCW3i3Eqd5rg6h"; private String appid;
@Value("${config-8timer.baidu-tic.secret}") @Value("${config-8timer.baidu-tic.secret}")
private static String secret = "UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS"; private String secret;
/** /**
* 获取百度token * 获取百度token
* @return * @return
*/ */
public static String getBaiduAccessToken(){ public String getBaiduAccessToken(){
StringBuffer url = new StringBuffer("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="); StringBuffer url = new StringBuffer("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=");
url = url.append(appid).append("&client_secret=").append(secret); url = url.append(appid).append("&client_secret=").append(secret);
ResponseEntity<String> response = new RestTemplate().exchange(url.toString(), HttpMethod.GET, null, String.class); ResponseEntity<String> response = new RestTemplate().exchange(url.toString(), HttpMethod.GET, null, String.class);
...@@ -42,7 +42,7 @@ public class BaiduTicUtil { ...@@ -42,7 +42,7 @@ public class BaiduTicUtil {
return new Gson().fromJson(response.getBody(), HashMap.class).get("access_token").toString(); return new Gson().fromJson(response.getBody(), HashMap.class).get("access_token").toString();
} }
public static ResponseEntity<String> getResumeByCvParser(BaiduTicResumeDto baiduTicResumeDto){ public ResponseEntity<String> getResumeByCvParser(BaiduTicResumeDto baiduTicResumeDto){
String url = "https://aip.baidubce.com/rpc/2.0/recruitment/v1/cvparser?access_token="+getBaiduAccessToken(); String url = "https://aip.baidubce.com/rpc/2.0/recruitment/v1/cvparser?access_token="+getBaiduAccessToken();
Map<String, Object> param = new HashMap<>(); Map<String, Object> param = new HashMap<>();
param.put("resume", baiduTicResumeDto); param.put("resume", baiduTicResumeDto);
...@@ -55,9 +55,4 @@ public class BaiduTicUtil { ...@@ -55,9 +55,4 @@ public class BaiduTicUtil {
return new RestTemplate().exchange(url, HttpMethod.POST,requestEntity, String.class); return new RestTemplate().exchange(url, HttpMethod.POST,requestEntity, String.class);
} }
public static void main(String[] args) {
BaiduTicResumeDto baiduTicResumeDto = BaiduTicResumeDto.builder().filename("邓志鸿.docx").filetype("docx").filedata(Base64.getStrFromPath("https://test-img.8timer.cn/6b8c7ec7-14b0-45e7-aa21-7acd0d45e612.docx")).build();
ResponseEntity<String> responseEntity = getResumeByCvParser(baiduTicResumeDto);
System.out.println(responseEntity.getBody());
}
} }
package cn.timer.api.utils.baidu; package cn.timer.api.utils.baidu;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -21,22 +22,12 @@ public class Base64 { ...@@ -21,22 +22,12 @@ public class Base64 {
/** /**
* 转化成Base64字符串 * 转化成Base64字符串
*/ */
public static String getStrFromPath(String imgPath) { public static String getStrFromPath(MultipartFile file) {
URL url = null;
InputStream in = null; InputStream in = null;
byte[] data = null; byte[] data = null;
try { try {
url = new URL(imgPath); in = file.getInputStream();
httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.connect();
httpUrl.getInputStream();
in = httpUrl.getInputStream();
data = new byte[in.available()]; data = new byte[in.available()];
in.read(data); in.read(data);
in.close(); in.close();
...@@ -46,6 +37,6 @@ public class Base64 { ...@@ -46,6 +37,6 @@ public class Base64 {
// 对字节数组Base64编码 // 对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder(); BASE64Encoder encoder = new BASE64Encoder();
// 返回Base64编码过再URLEncode的字节数组字符串 // 返回Base64编码过再URLEncode的字节数组字符串
return URLEncoder.encode(encoder.encode(data)); return encoder.encode(data);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment