招聘部分功能完善

This commit is contained in:
Unique-Jerry 2023-11-10 18:28:31 +08:00
parent 296aa00247
commit 84232c9860
14 changed files with 901 additions and 25 deletions

15
pom.xml
View File

@ -101,7 +101,22 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.4</version> <version>2.4</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0</version>
</dependency>
</dependencies> </dependencies>

View File

@ -1,18 +1,22 @@
package com.yzdx.AiInterviewer.controller; package com.yzdx.AiInterviewer.controller;
import com.yzdx.AiInterviewer.comment.R; import com.yzdx.AiInterviewer.comment.R;
import com.yzdx.AiInterviewer.entity.Company;
import com.yzdx.AiInterviewer.entity.JobEntity; import com.yzdx.AiInterviewer.entity.JobEntity;
import com.yzdx.AiInterviewer.entity.dto.JobDto; import com.yzdx.AiInterviewer.entity.dto.JobDto;
import com.yzdx.AiInterviewer.entity.dto.JobSettingDto; import com.yzdx.AiInterviewer.entity.dto.JobSettingDto;
import com.yzdx.AiInterviewer.service.CompanyService;
import com.yzdx.AiInterviewer.service.InterviewSettingService; import com.yzdx.AiInterviewer.service.InterviewSettingService;
import com.yzdx.AiInterviewer.service.JobListService; import com.yzdx.AiInterviewer.service.JobListService;
import com.yzdx.AiInterviewer.utiles.MyStringUtils; import com.yzdx.AiInterviewer.utiles.MyStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList; import javax.servlet.http.HttpSession;
import java.util.List; import java.io.File;
import java.util.Map; import java.io.IOException;
import java.util.*;
@RestController @RestController
@ -23,6 +27,8 @@ public class RecruitmentController {
private JobListService jobListService; private JobListService jobListService;
@Autowired @Autowired
private InterviewSettingService interviewSettingService; private InterviewSettingService interviewSettingService;
@Autowired
private CompanyService companyService;
@PostMapping("/add_job") @PostMapping("/add_job")
public R addJob(@RequestBody Map<String,Object> addInfo){ public R addJob(@RequestBody Map<String,Object> addInfo){
@ -204,4 +210,67 @@ public class RecruitmentController {
List<JobSettingDto> jobSettingList = interviewSettingService.getJobSettingList(encoding); List<JobSettingDto> jobSettingList = interviewSettingService.getJobSettingList(encoding);
return R.success(jobSettingList); return R.success(jobSettingList);
} }
@GetMapping("/delete_jobJobSetting")
public R deleteJobSetting(Integer id){
Integer rows = interviewSettingService.deleteJobSetting(id);
if(rows==-1){
R.error("删除失败,请联系管理员");
}
return R.success("删除成功!");
}
@PostMapping("/update_jobJobSetting")
public R updateJobSetting(@RequestBody Map<String,Object> updateInfo){
Integer id = (Integer) updateInfo.get("id");
Integer jobId = (Integer) updateInfo.get("jobId");
Integer imagesId = (Integer) updateInfo.get("imagesId");
Integer backgroundId = (Integer) updateInfo.get("backgroundId");
Integer logoId = (Integer) updateInfo.get("logoId");
Integer Professional = null;
try {
Professional = (Integer) updateInfo.get("professional");
} catch (Exception e) {
}
Integer Comprehensive = null;
try {
Comprehensive = (Integer) updateInfo.get("comprehensive");
} catch (Exception e) {
}
Integer Psychology = null;
try {
Psychology = (Integer) updateInfo.get("psychology");
} catch (Exception e) {
}
Integer userId = (Integer) updateInfo.get("userId");
String jobPromote = (String) updateInfo.get("jobPromote");
String encoding = (String) updateInfo.get("encoding");
Integer rows= interviewSettingService.updateJobSetting(id,jobId, imagesId, backgroundId, logoId, Professional, Comprehensive, Psychology, userId, jobPromote, encoding);
if(rows==-1){
return R.error("修改失败");
}
return R.success("修改成功");
}
@GetMapping("/get_companyDetail")
public R getCompanyDetail(String encoding){
if(encoding==null){
return R.error("获取失败");
}
Company companyDetail = companyService.getCompanyDetail(encoding);
if(companyDetail==null){
return R.error("获取失败");
}
return R.success(companyDetail);
}
} }

View File

@ -1,7 +1,12 @@
package com.yzdx.AiInterviewer.controller; package com.yzdx.AiInterviewer.controller;
import com.yzdx.AiInterviewer.comment.R; import com.yzdx.AiInterviewer.comment.R;
import com.yzdx.AiInterviewer.entity.CompanyImage;
import com.yzdx.AiInterviewer.mapper.CompanyImageMapper;
import com.yzdx.AiInterviewer.utiles.ParseResumeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -17,9 +22,14 @@ import java.util.*;
@Slf4j @Slf4j
public class UploadController { public class UploadController {
@Autowired
private CompanyImageMapper companyImageMapper;
//设置上传文件的最大大小 //设置上传文件的最大大小
public static final int MAX_SIZE=10*1024*1024; public static final int MAX_SIZE=10*1024*1024;
public static final String UPLOAD_PATH = "D:\\vue学习\\Ai-interviewer-ui\\src\\upload";//获取上传文件的路径获取项目中名为upload的文件夹 public static final String UPLOAD_AVATAR_PATH = "D:\\vueStudy\\Ai-interviewer-ui\\src\\upload\\picture";//获取上传文件的路径获取项目中名为upload的文件夹
public static final String UPLOAD_RESUME_PATH = "D:\\vueStudy\\Ai-interviewer-ui\\src\\upload\\resume";//获取上传文件的路径获取项目中名为upload的文件夹
//设置文件的类型 //设置文件的类型
public static final List<String> AVATAR_TYPE=new ArrayList<>(); public static final List<String> AVATAR_TYPE=new ArrayList<>();
@ -31,8 +41,8 @@ public class UploadController {
AVATAR_TYPE.add("image/jpeg"); AVATAR_TYPE.add("image/jpeg");
} }
@PostMapping("/upload_picture") @PostMapping("/upload_companyImage")
public R upLoadPicture(HttpSession session, @RequestParam("file") MultipartFile file){ public R upLoadPicture(HttpSession session, @RequestParam("file") MultipartFile file ,String encoding){
//MultipartFile是spring提供的类可以接收所有的文件的类 //MultipartFile是spring提供的类可以接收所有的文件的类
@ -51,11 +61,11 @@ public class UploadController {
} }
// String uploadPath = session.getServletContext().getRealPath("upload");//获取上传文件的路径获取项目中名为upload的文件夹 // String uploadPath = session.getServletContext().getRealPath("upload");//获取上传文件的路径获取项目中名为upload的文件夹
String uploadPath = "D:\\vue学习\\Ai-interviewer-ui\\src\\upload";//获取上传文件的路径获取项目中名为upload的文件夹 // String uploadPath = "D:\\vue学习\\Ai-interviewer-ui\\src\\upload";//获取上传文件的路径获取项目中名为upload的文件夹
//
// log.info(uploadPath);
log.info(uploadPath); File dir=new File(UPLOAD_AVATAR_PATH);//指向名为upload文件夹
File dir=new File(UPLOAD_PATH);//指向名为upload文件夹
if(!dir.exists()){ if(!dir.exists()){
dir.mkdirs();//若不存在则创建该文件夹 dir.mkdirs();//若不存在则创建该文件夹
@ -80,15 +90,15 @@ public class UploadController {
return R.error("文件存储出现异常"); return R.error("文件存储出现异常");
} }
String RealFilePath="http://localhost:5173/src/upload/"+filename; String RealFilePath="http://localhost:5173/src/upload/picture/"+filename;
Map<String,Object> data=new HashMap<>();
data.put("image",RealFilePath);
data.put("filename",filename);
return R.success(data);//返回图片存储在服务器的地址
CompanyImage companyImage=new CompanyImage();
companyImage.setImage(RealFilePath);
companyImage.setFilename(filename);
companyImage.setEncoding(encoding);
companyImageMapper.insert(companyImage);
return R.success(companyImage);//返回图片存储在服务器的地址
} }
@GetMapping("/delete_picture") @GetMapping("/delete_picture")
@ -98,7 +108,7 @@ public class UploadController {
} }
try { try {
File folder = new File(UPLOAD_PATH); File folder = new File(UPLOAD_AVATAR_PATH);
File[] files = folder.listFiles(); File[] files = folder.listFiles();
for(File file:files){ for(File file:files){
if(file.getName().equals(imagePath)){ if(file.getName().equals(imagePath)){
@ -112,4 +122,142 @@ public class UploadController {
} }
@PostMapping("/upload_resume")
public R uploadResume(HttpSession session, @RequestParam("file") MultipartFile file){
if(file.isEmpty()){
return R.error("请选择文件");
} }
if (file.getSize() >50*1024*1024){//file.getSize()获取接收文件的大小
return R.error("文件大小超出最大限制");
}
// String uploadPath = session.getServletContext().getRealPath("upload");//获取上传文件的路径获取项目中名为upload的文件夹
// String uploadPath = "D:\\vue学习\\Ai-interviewer-ui\\src\\upload";//获取上传文件的路径获取项目中名为upload的文件夹
//
// log.info(uploadPath);
File dir=new File(UPLOAD_RESUME_PATH);//指向名为upload文件夹
if(!dir.exists()){
dir.mkdirs();//若不存在则创建该文件夹
}
String originalFilename = file.getOriginalFilename();//获取文件的真实文件名
int index = originalFilename.lastIndexOf(".");//获取文件的后缀名.的位置
String substring = originalFilename.substring(index);//返回文件类型名 例如.jpg
String filename = UUID.randomUUID().toString().toUpperCase()+substring;//新创建的文件名
File dest=new File(dir,filename);//创建一个空的文件
try {
file.transferTo(dest);
} catch (IOException e) {
return R.error("文件存储出现异常");
}
String RealFilePath="http://localhost:5173/src/upload/resume/"+filename;
ParseResumeUtil.ParseChineseResume(UPLOAD_RESUME_PATH+"\\"+filename);
Map<String,Object> data=new HashMap<>();
data.put("resume",RealFilePath);
data.put("filename",filename);
return R.success(data);//返回图片存储在服务器的地址
}
@GetMapping("/delete_resume")
public R deleteResume(String resumePath){
if(resumePath==null||resumePath.equals("")){
return R.error("删除失败!");
}
try {
File folder = new File(UPLOAD_AVATAR_PATH);
File[] files = folder.listFiles();
for(File file:files){
if(file.getName().equals(resumePath)){
file.delete();
}
}
return R.success("删除成功");
} catch (Exception e) {
return R.error("删除失败");
}
}
@PostMapping("/upload_picture")
public R uploadCompanyImage(HttpSession session, @RequestParam("file") MultipartFile file){
//MultipartFile是spring提供的类可以接收所有的文件的类
log.info(file.getContentType());
if(file.isEmpty()){
return R.error("请选择文件");
}
if (file.getSize() >MAX_SIZE){//file.getSize()获取接收文件的大小
return R.error("文件大小超出最大限制");
}
if(!AVATAR_TYPE.contains(file.getContentType())){//自定义接收文件的类型
return R.error("文件类型不匹配");
}
// String uploadPath = session.getServletContext().getRealPath("upload");//获取上传文件的路径获取项目中名为upload的文件夹
// String uploadPath = "D:\\vue学习\\Ai-interviewer-ui\\src\\upload";//获取上传文件的路径获取项目中名为upload的文件夹
//
// log.info(uploadPath);
File dir=new File(UPLOAD_AVATAR_PATH);//指向名为upload文件夹
if(!dir.exists()){
dir.mkdirs();//若不存在则创建该文件夹
}
String originalFilename = file.getOriginalFilename();//获取文件的真实文件名
int index = originalFilename.lastIndexOf(".");//获取文件的后缀名.的位置
String substring = originalFilename.substring(index);//返回文件类型名 例如.jpg
String filename= UUID.randomUUID().toString().toUpperCase()+substring;//新创建的文件名
File dest=new File(dir,filename);//创建一个空的文件
try {
file.transferTo(dest);
} catch (IOException e) {
return R.error("文件存储出现异常");
}
String RealFilePath="http://localhost:5173/src/upload/picture/"+filename;
Map<String,Object> data=new HashMap<>();
data.put("image",RealFilePath);
data.put("filename",filename);
return R.success(data);//返回图片存储在服务器的地址
}
}

View File

@ -19,15 +19,14 @@ public class Company extends BaseEntity{
private Integer id; private Integer id;
@ApiModelProperty("公司名称") @ApiModelProperty("公司名称")
private String companyName; private String companyName;
@ApiModelProperty("公司全称")
@TableField(value = "company_allname")
private String companyAllName;
@ApiModelProperty("公司详情") @ApiModelProperty("公司详情")
private String companyDetail; private String companyDetail;
@ApiModelProperty("公司类型") @ApiModelProperty("公司类型")
private String type; private String type;
@ApiModelProperty("公司地址") @ApiModelProperty("公司地址")
private String address; private String address;
@ApiModelProperty("公司详细地址")
private String addressDetail;
@ApiModelProperty("公司待遇") @ApiModelProperty("公司待遇")
private String treatment; private String treatment;
@ApiModelProperty("法定代表人") @ApiModelProperty("法定代表人")

View File

@ -0,0 +1,11 @@
package com.yzdx.AiInterviewer.entity;
import lombok.Data;
@Data
public class CompanyImage {
private Integer id;
private String filename;
private String image;
private String encoding;
}

View File

@ -0,0 +1,9 @@
package com.yzdx.AiInterviewer.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yzdx.AiInterviewer.entity.CompanyImage;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CompanyImageMapper extends BaseMapper<CompanyImage> {
}

View File

@ -0,0 +1,15 @@
package com.yzdx.AiInterviewer.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yzdx.AiInterviewer.entity.Company;
public interface CompanyService extends IService<Company> {
/**
* 获取公司详情
* @param encoding 公司编码
* @return 公司详情对象
*
* */
Company getCompanyDetail(String encoding);
}

View File

@ -35,8 +35,43 @@ public interface InterviewSettingService extends IService<InterviewSetting> {
String encoding); String encoding);
/** /**
* 获取岗位设置列表 * 获取岗位设置列表
* * @param encoding 公司编码
* * @return 返回JobSettingDto列表
* */ * */
List<JobSettingDto> getJobSettingList(String encoding); List<JobSettingDto> getJobSettingList(String encoding);
/**
* 根据没你事设置id删除面试设置
* @param id 岗位设置的id
* @return 返回影响的行数
* */
Integer deleteJobSetting(Integer id);
/**
* 修改岗位设置
* @param id 岗位设置id
* @param jobId 岗位id
* @param imagesId 形象id
* @param backgroundId 面试背景id
* @param logoId 公司logoId
* @param Professional 专业题库id
* @param Comprehensive 综合面试题库id
* @param Psychology 心理测试id
* @param userId 创建人id
* @param jobPromote 岗位promote
* @param encoding 公司编码
* @return 影响的行数
* */
Integer updateJobSetting(Integer id,
Integer jobId,
Integer imagesId,
Integer backgroundId,
Integer logoId,
Integer Professional,
Integer Comprehensive,
Integer Psychology,
Integer userId,
String jobPromote,
String encoding);
} }

View File

@ -0,0 +1,27 @@
package com.yzdx.AiInterviewer.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzdx.AiInterviewer.entity.Company;
import com.yzdx.AiInterviewer.mapper.CompanyMapper;
import com.yzdx.AiInterviewer.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {
@Autowired
private CompanyMapper companyMapper;
@Override
public Company getCompanyDetail(String encoding) {
LambdaQueryWrapper<Company> queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.eq(Company::getEncoding,encoding);
Company company = companyMapper.selectOne(queryWrapper);
return company;
}
}

View File

@ -150,4 +150,46 @@ public class InterviewSettingServiceImpl extends ServiceImpl<InterviewSettingMap
return jobSettingDtoList; return jobSettingDtoList;
} }
@Override
public Integer deleteJobSetting(Integer id) {
LambdaQueryWrapper<InterviewSetting> queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.eq(InterviewSetting::getId,id);
InterviewSetting findJobSetting = interviewSettingMapper.selectOne(queryWrapper);
if(findJobSetting==null){
return -1;
}
Integer rows = interviewSettingMapper.deleteById(id);
return rows;
}
@Override
public Integer updateJobSetting(Integer id, Integer jobId, Integer imagesId, Integer backgroundId, Integer logoId, Integer Professional, Integer Comprehensive, Integer Psychology, Integer userId, String jobPromote, String encoding) {
//根据id查找岗位设置
LambdaQueryWrapper<InterviewSetting> queryWrapper=new LambdaQueryWrapper<>();
queryWrapper.eq(InterviewSetting::getId,id);
InterviewSetting findSetting = interviewSettingMapper.selectOne(queryWrapper);
if(findSetting==null){
return -1;
}
findSetting.setImagesId(imagesId);
findSetting.setLogoId(logoId);
findSetting.setBackgroundId(backgroundId);
findSetting.setPsychology(Psychology);
findSetting.setProfessional(Professional);
findSetting.setComprehensive(Comprehensive);
findSetting.setUpdateTime(TimeUtil.getTime());
findSetting.setUpdateUser(userId);
return interviewSettingMapper.updateById(findSetting);
}
} }

View File

@ -0,0 +1,468 @@
package com.yzdx.AiInterviewer.utiles;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Slf4j
public class HttpUtil {
private HttpUtil(){
}
private static void configTimeout(HttpClient httpClient){
HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams();
params.setConnectionTimeout(20000);
params.setSoTimeout(20000);
}
public static String post(String url, String reqParam) throws Exception {
HttpClient httpClient = new HttpClient();
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
RequestEntity entity = new StringRequestEntity(reqParam);
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
return respResult;
}
public static String jsonPost(String url, String reqParam) throws Exception {
HttpClient httpClient = new HttpClient();
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
RequestEntity entity = new StringRequestEntity(reqParam, "application/json", "utf-8");
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
public static String post(String url, String reqParam, String charSet) throws Exception {
HttpClient httpClient = new HttpClient();
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
RequestEntity entity = new StringRequestEntity(reqParam);
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
public static String get(String url, String reqParam) throws Exception {
// reqParam = URLEncoder.encode(reqParam, "UTF-8");
HttpClient httpClient = new HttpClient();
GetMethod method;
if(StringUtil.isNullOrEmpty(reqParam)){
// 请求url及参数
method = new GetMethod(url);
}
else {
System.out.println("------请求URL"+url + "?" +reqParam);
// 请求url及参数
method = new GetMethod(url + "?" +reqParam);
}
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
// 执行get请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
public static String get(String url, String reqParam, String charSet) throws Exception {
// reqParam = URLEncoder.encode(reqParam, "UTF-8");
HttpClient httpClient = new HttpClient();
GetMethod method;
if(StringUtil.isNullOrEmpty(reqParam)){
// 请求url及参数
method = new GetMethod(url);
}
else {
System.out.println("请求URL字符串"+url + "?" +reqParam);
// 请求url及参数
method = new GetMethod(url + "?" +reqParam);
}
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
// 执行get请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
/**
* 添加header "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
*/
public static String postHeader(String url, String reqParam) throws Exception {
HttpClient httpClient = new HttpClient();
HttpClientParams params = new HttpClientParams();
//另外设置http client的重试次数默认是3次当前是禁用掉如果项目量不到这个默认即可
params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
httpClient.setParams(params);
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
RequestEntity entity = new StringRequestEntity(reqParam);
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
@SuppressWarnings({ "deprecation", "unused" })
private static HttpPost postForm(String url, Map<String, String> params){
HttpPost httpost = new HttpPost(url);
List<NameValuePair> nvps = new ArrayList <>();
Set<String> keySet = params.keySet();
for(String key : keySet) {
nvps.add(new BasicNameValuePair(key, params.get(key)));
}
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return httpost;
}
/**
* post请求<设置请求头>
* @param url 请求地址
* @param reqParamName 请求参数名称
* @param reqParamValue 请求参数值
* @param charSet 编码格式
* @author yew
* date 2017年7月26日 下午2:11:40
*/
public static String postRequset(String url, String reqParamName, String reqParamValue, String charSet) throws Exception {
HttpClient httpClient = new HttpClient();
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
//设置参数请求头
method.setParameter(reqParamName, reqParamValue);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
public static String jsonPostHeader(String url, String reqParam, String accessToken, String version) throws Exception {
HttpClient httpClient = new HttpClient();
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader("accessToken", accessToken);
method.addRequestHeader("version", version);
RequestEntity entity = new StringRequestEntity(reqParam, "application/json", "utf-8");
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
public static String jsonPostHeader(String url, String reqParam) throws Exception {
HttpClient httpClient = new HttpClient();
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
RequestEntity entity = new StringRequestEntity(reqParam, "application/xml", "utf-8");
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
/**
* post key-value形式传参
* @param url 请求url
* @param paramsMap 请求的map数据
* @return
*/
public static String postFormMap(String url, Map<String, Object> paramsMap) {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
//配置连接超时时间
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.setSocketTimeout(5000)
.setRedirectsEnabled(true)
.build();
HttpPost httpPost = new HttpPost(url);
//设置超时时间
httpPost.setConfig(requestConfig);
//装配post请求参数
List<NameValuePair> list = new ArrayList<>();
for (String key : paramsMap.keySet()) {
list.add(new BasicNameValuePair(key, String.valueOf(paramsMap.get(key))));
}
try {
//将参数进行编码为合适的格式,如将键值对编码为param1=value1&param2=value2
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, "utf-8");
httpPost.setEntity(urlEncodedFormEntity);
//执行 post请求
CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpPost);
String result = "";
if (null != closeableHttpResponse) {
System.out.println(closeableHttpResponse.getStatusLine().getStatusCode());
if (closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity = closeableHttpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
} else {
result = "Error Response" + closeableHttpResponse.getStatusLine().getStatusCode();
}
}
log.info("请求{}返回:{}", url, result);
return result;
} catch (ClientProtocolException e) {
e.printStackTrace();
return "协议异常";
} catch (ParseException e) {
e.printStackTrace();
return "解析异常";
} catch (IOException e) {
e.printStackTrace();
return "传输异常";
} finally {
try {
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @param url
* @param reqParam 请求参数
* @param headerParam 请求头参数
* @return
*/
public static String post(String url, String reqParam,Map<String,Object> headerParam) throws Exception {
HttpClient httpClient = new HttpClient();
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
// 请求url
PostMethod method = new PostMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
for (Map.Entry<String, Object> vo : headerParam.entrySet()) {
method.addRequestHeader(vo.getKey(),vo.getKey());
}
RequestEntity entity = new StringRequestEntity(reqParam);
method.setRequestEntity(entity);
// 执行post请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
return respResult;
}
public static String get(String url, Map<String,Object> headerParam) throws Exception {
HttpClient httpClient = new HttpClient();
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
GetMethod method;
method = new GetMethod(url);
configTimeout(httpClient);
// 设置请求编码UTF-8
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
method.addRequestHeader(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
for (Map.Entry<String, Object> vo : headerParam.entrySet()) {
method.addRequestHeader(vo.getKey(),vo.getKey());
}
// 执行get请求
httpClient.executeMethod(method);
// 请求返回
String respResult = method.getResponseBodyAsString();
// 释放连接
method.releaseConnection();
log.info("请求{}返回:{}", url, respResult);
return respResult;
}
}

View File

@ -0,0 +1,28 @@
package com.yzdx.AiInterviewer.utiles;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class ParseResumeUtil {
public static Map<String,Object> ParseChineseResume(String filePath){
Map<String,Object> data;
String s=null;
try {
s = HttpUtil.get("http://127.0.0.1:5000/getParseResume?filePath="+filePath, "");
} catch (Exception e) {
e.printStackTrace();
}
JSONObject jsonObject = JSON.parseObject(s);
data = jsonObject.getInnerMap();
return data;
}
}

View File

@ -0,0 +1,10 @@
package com.yzdx.AiInterviewer.utiles;
import java.util.Map;
public class ParseTest {
public static void main(String[] args) {
Map<String, Object> stringObjectMap = ParseResumeUtil.ParseChineseResume("D:\\94011899\\djangoProject2\\submit-file\\files\\101.docx");
System.out.println(stringObjectMap);
}
}

View File

@ -25,5 +25,5 @@ spring:
servlet: servlet:
multipart: multipart:
max-file-size: 10MB #单个文件大小限制 max-file-size: 50MB #单个文件大小限制
max-request-size: 10MB #总文件大小限制(允许存储文件的文件夹大小) max-request-size: 50MB #总文件大小限制(允许存储文件的文件夹大小)