添加岗位模板下载,岗位模板上传功能
This commit is contained in:
@@ -5,7 +5,9 @@ import com.ruoyi.cms.domain.*;
|
||||
import com.ruoyi.cms.domain.query.ESJobSearch;
|
||||
import com.ruoyi.cms.domain.vo.CandidateVO;
|
||||
import com.ruoyi.cms.domain.vo.CompanyVo;
|
||||
import com.ruoyi.cms.domain.vo.JobExcelVo;
|
||||
import com.ruoyi.cms.service.*;
|
||||
import com.ruoyi.cms.util.EasyExcelUtils;
|
||||
import com.ruoyi.cms.util.RoleUtils;
|
||||
import com.ruoyi.cms.util.StringUtil;
|
||||
import com.ruoyi.cms.util.sensitiveWord.SensitiveWordChecker;
|
||||
@@ -24,12 +26,15 @@ import com.ruoyi.common.utils.bean.BeanUtils;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -358,4 +363,82 @@ public class CmsJobController extends BaseController
|
||||
}
|
||||
return AjaxResult.success("此岗位已存在!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用上传请求(单个)
|
||||
*/
|
||||
@PostMapping("/uploadFile")
|
||||
@ApiOperation("岗位批量上传")
|
||||
public AjaxResult uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
return AjaxResult.error("上传文件不能为空");
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName == null || !fileName.endsWith(".xlsx") && !fileName.endsWith(".xls")) {
|
||||
return AjaxResult.error("请上传Excel格式的文件");
|
||||
}
|
||||
|
||||
try (InputStream inputStream = file.getInputStream()){
|
||||
List<JobExcelVo> allExcelVoList = new ArrayList<>();
|
||||
EasyExcelUtils.readExcelByBatch(inputStream, JobExcelVo.class, 100, list -> {
|
||||
allExcelVoList.addAll(list);
|
||||
});
|
||||
if (CollectionUtils.isEmpty(allExcelVoList)) {
|
||||
throw new Exception("Excel文件中无有效数据");
|
||||
}
|
||||
jobService.uploadFileJob(allExcelVoList);
|
||||
return AjaxResult.success("已上传!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
* @param request
|
||||
* @param response
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/downloadModel")
|
||||
public void downloadModel(HttpServletRequest request, HttpServletResponse response)throws Exception{
|
||||
String name = "模板.xlsx";
|
||||
String pathFile="/data/downloadmodel/"+name;
|
||||
File url = new File(pathFile);
|
||||
|
||||
String resMsg = "";
|
||||
try {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
name = new String(name.getBytes("gb2312"), "ISO8859-1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
response.reset();
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment; filename="+ name);
|
||||
response.setHeader("Pragma", "public");
|
||||
response.setHeader("Cache-Control", "max-age=0");
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(url);
|
||||
} catch (FileNotFoundException e1) {
|
||||
resMsg = "文件未找到";
|
||||
e1.printStackTrace();
|
||||
response.getWriter().write(resMsg + ":" + name);
|
||||
}
|
||||
OutputStream ou = response.getOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int i = -1;
|
||||
while ((i = in.read(buffer)) != -1) {
|
||||
ou.write(buffer, 0, i);
|
||||
}
|
||||
ou.flush();
|
||||
ou.close();
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user