This commit is contained in:
parent
c2b1dff5cf
commit
4fe9de70ae
28
pom.xml
28
pom.xml
|
@ -233,6 +233,34 @@
|
||||||
<version>1.1.0</version>
|
<version>1.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>ooxml-schemas</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.afterturn</groupId>
|
||||||
|
<artifactId>easypoi-base</artifactId>
|
||||||
|
<version>4.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.afterturn</groupId>
|
||||||
|
<artifactId>easypoi-web</artifactId>
|
||||||
|
<version>4.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.afterturn</groupId>
|
||||||
|
<artifactId>easypoi-annotation</artifactId>
|
||||||
|
<version>4.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--pdf-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.docx4j</groupId>
|
||||||
|
<artifactId>docx4j-export-fo</artifactId>
|
||||||
|
<version>6.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.ydool.staff.controller;
|
package com.ydool.staff.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||||
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
|
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
|
||||||
|
@ -9,7 +8,6 @@ import com.ydool.common.base.BaseController;
|
||||||
import com.ydool.common.constant.UrlConstant;
|
import com.ydool.common.constant.UrlConstant;
|
||||||
import com.ydool.common.data.dto.AjaxResult;
|
import com.ydool.common.data.dto.AjaxResult;
|
||||||
import com.ydool.staff.dto.RecruitmentDto;
|
import com.ydool.staff.dto.RecruitmentDto;
|
||||||
import com.ydool.staff.entity.Audit;
|
|
||||||
import com.ydool.staff.request.RecruitmentRequest;
|
import com.ydool.staff.request.RecruitmentRequest;
|
||||||
import com.ydool.staff.service.IAuditService;
|
import com.ydool.staff.service.IAuditService;
|
||||||
import com.ydool.staff.service.IRecruitmentService;
|
import com.ydool.staff.service.IRecruitmentService;
|
||||||
|
@ -20,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
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 javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(UrlConstant.RECRUITMENT)
|
@RequestMapping(UrlConstant.RECRUITMENT)
|
||||||
|
@ -65,4 +65,10 @@ public class RecruitmentController extends BaseController {
|
||||||
public AjaxResult waiting() {
|
public AjaxResult waiting() {
|
||||||
return auditService.waitingAudit(getPage());
|
return auditService.waitingAudit(getPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@ApiOperation("招聘导出")
|
||||||
|
public void export(String id, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
recruitmentService.export(id, request, response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ydool.staff.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ExportRecruitmentDto {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "企业名称")
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "原核定用工指标人数")
|
||||||
|
private Long checkNumber;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "在职人数")
|
||||||
|
private Long activeStaff;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "剩余指标人数")
|
||||||
|
private Long residualNumber;
|
||||||
|
|
||||||
|
private List<RecruitmentListDto> recruitmentListDtoList;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.ydool.staff.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RecruitmentListDto {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "部门")
|
||||||
|
private String deptId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "岗位职务")
|
||||||
|
private String position;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "名额")
|
||||||
|
private Long places;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "条件要求")
|
||||||
|
private String requirements;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.ydool.staff.excel;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||||
|
import com.alibaba.excel.annotation.write.style.ContentStyle;
|
||||||
|
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
|
||||||
|
import com.alibaba.excel.annotation.write.style.HeadStyle;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@HeadRowHeight(20)
|
||||||
|
@ColumnWidth(20)
|
||||||
|
@HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER)
|
||||||
|
@ContentStyle(verticalAlignment = VerticalAlignment.CENTER)
|
||||||
|
public class ExcelRecruitment {
|
||||||
|
|
||||||
|
@ExcelProperty("企业名称")
|
||||||
|
private String companyId;
|
||||||
|
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
private String deptId;
|
||||||
|
|
||||||
|
@ExcelProperty("岗位")
|
||||||
|
private String position;
|
||||||
|
|
||||||
|
@ExcelProperty("名额")
|
||||||
|
private Long places;
|
||||||
|
|
||||||
|
@ExcelProperty("要求")
|
||||||
|
private String requirements;
|
||||||
|
}
|
|
@ -1,13 +1,11 @@
|
||||||
package com.ydool.staff.service;
|
package com.ydool.staff.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.ydool.common.data.dto.AjaxResult;
|
import com.ydool.common.data.dto.AjaxResult;
|
||||||
import com.ydool.staff.entity.Recruitment;
|
|
||||||
import com.ydool.staff.request.RecruitmentRequest;
|
import com.ydool.staff.request.RecruitmentRequest;
|
||||||
import com.ydool.staff.request.RecruitmentSearch;
|
|
||||||
import com.ydool.system.request.IdsRequest;
|
import com.ydool.system.request.IdsRequest;
|
||||||
|
|
||||||
import java.util.List;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
public interface IRecruitmentService {
|
public interface IRecruitmentService {
|
||||||
|
|
||||||
|
@ -32,4 +30,6 @@ public interface IRecruitmentService {
|
||||||
*/
|
*/
|
||||||
AjaxResult selectRecruitmentById(String id);
|
AjaxResult selectRecruitmentById(String id);
|
||||||
|
|
||||||
|
void export(String id, HttpServletRequest request, HttpServletResponse response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
package com.ydool.staff.service.impl;
|
package com.ydool.staff.service.impl;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.word.WordExportUtil;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.spire.doc.Document;
|
||||||
|
import com.spire.doc.FileFormat;
|
||||||
import com.ydool.common.cache.ConfigCache;
|
import com.ydool.common.cache.ConfigCache;
|
||||||
import com.ydool.common.constant.ArgsConst;
|
import com.ydool.common.constant.ArgsConst;
|
||||||
import com.ydool.common.data.dto.AjaxResult;
|
import com.ydool.common.data.dto.AjaxResult;
|
||||||
|
import com.ydool.common.exception.ResultException;
|
||||||
import com.ydool.staff.dto.RecruitmentDto;
|
import com.ydool.staff.dto.RecruitmentDto;
|
||||||
import com.ydool.staff.entity.*;
|
import com.ydool.staff.entity.*;
|
||||||
import com.ydool.common.base.BaseService;
|
import com.ydool.common.base.BaseService;
|
||||||
|
@ -25,14 +29,20 @@ import com.ydool.system.entity.User;
|
||||||
import com.ydool.system.mapper.ConfigMapper;
|
import com.ydool.system.mapper.ConfigMapper;
|
||||||
import com.ydool.system.mapper.UserMapper;
|
import com.ydool.system.mapper.UserMapper;
|
||||||
import com.ydool.system.request.IdsRequest;
|
import com.ydool.system.request.IdsRequest;
|
||||||
|
import com.ydool.system.service.impl.DeptServiceImpl;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -47,6 +57,7 @@ public class RecruitmentServiceImpl extends BaseService<RecruitmentMapper, Recru
|
||||||
|
|
||||||
private static final AtomicInteger counter = new AtomicInteger(0);
|
private static final AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
|
private final String filepath = System.getProperty("user.dir");
|
||||||
@Autowired
|
@Autowired
|
||||||
RecruitmentMapper recruitmentMapper;
|
RecruitmentMapper recruitmentMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -61,6 +72,8 @@ public class RecruitmentServiceImpl extends BaseService<RecruitmentMapper, Recru
|
||||||
private ConfigMapper configMapper;
|
private ConfigMapper configMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
|
@Autowired
|
||||||
|
private DeptServiceImpl deptService;
|
||||||
|
|
||||||
public static String getNextId() {
|
public static String getNextId() {
|
||||||
int value = counter.incrementAndGet();
|
int value = counter.incrementAndGet();
|
||||||
|
@ -125,5 +138,110 @@ public class RecruitmentServiceImpl extends BaseService<RecruitmentMapper, Recru
|
||||||
return AjaxResult.ok().data(recruitmentRequest);
|
return AjaxResult.ok().data(recruitmentRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void export(String id, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
throw new ResultException("id不能为空!");
|
||||||
|
}
|
||||||
|
File uploadFile = new File(filepath);
|
||||||
|
String wordDir = "";
|
||||||
|
if (!uploadFile.exists()) {
|
||||||
|
uploadFile.mkdirs();
|
||||||
|
}
|
||||||
|
if (!filepath.endsWith("/")) {
|
||||||
|
wordDir = filepath + "/upload/word";
|
||||||
|
}
|
||||||
|
File tf = null;
|
||||||
|
try {
|
||||||
|
tf = new File(URLDecoder.decode(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("doc/象山县国有企业人员招聘报备表.docx")).getPath(), "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
System.out.println("tf.getPath() = " + tf.getPath());
|
||||||
|
Organization organization = organizationMapper.selectById(id);
|
||||||
|
CompanyName companyName = companyNameMapper.selectById(organization.getCompanyId());
|
||||||
|
List<Recruitment> recruitments = recruitmentMapper.selectList(Wrappers.lambdaQuery(Recruitment.class).eq(Recruitment::getCompanyId, organization.getId()));
|
||||||
|
long sum = recruitments.stream().mapToLong(Recruitment::getPlaces).sum();
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("name", companyName.getCompanyName());
|
||||||
|
params.put("check", organization.getCheckNumber());
|
||||||
|
params.put("staff", organization.getActiveStaff());
|
||||||
|
params.put("number", organization.getResidualNumber());
|
||||||
|
params.put("sum", sum);
|
||||||
|
params.put("list", recruitments);
|
||||||
|
|
||||||
|
String fileName = "象山县国有企业人员招聘报备表.docx";
|
||||||
|
String word = exportWord(tf.getPath(), wordDir, fileName, params);
|
||||||
|
String pdfFileName = "象山县国有企业人员招聘报备表.pdf";
|
||||||
|
|
||||||
|
Document document = new Document();
|
||||||
|
document.loadFromFile(word);
|
||||||
|
document.saveToFile(wordDir + "/" + pdfFileName, FileFormat.PDF);
|
||||||
|
|
||||||
|
try {
|
||||||
|
response.setContentType("application/force-download");// 设置强制下载不打开
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(pdfFileName, "UTF-8")); // 中文名称下载
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
FileInputStream fis = null;
|
||||||
|
BufferedInputStream bis = null;
|
||||||
|
OutputStream outputStream = null;
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(wordDir + File.separator + pdfFileName);
|
||||||
|
bis = new BufferedInputStream(fis);
|
||||||
|
outputStream = response.getOutputStream();
|
||||||
|
int i = bis.read(buffer);
|
||||||
|
while (i != -1) {
|
||||||
|
outputStream.write(buffer, 0, i);
|
||||||
|
i = bis.read(buffer);
|
||||||
|
}
|
||||||
|
outputStream.flush();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (outputStream != null) {
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
if (bis != null) {
|
||||||
|
bis.close();
|
||||||
|
}
|
||||||
|
if (fis != null) {
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String exportWord(String templatePath, String saveDir, String fileName, Map<String, Object> params) {
|
||||||
|
org.springframework.util.Assert.notNull(templatePath, "模板路径不能为空");
|
||||||
|
org.springframework.util.Assert.notNull(saveDir, "临时文件路径不能为空");
|
||||||
|
org.springframework.util.Assert.notNull(fileName, "导出文件名不能为空");
|
||||||
|
Assert.isTrue(fileName.endsWith(".docx"), "word导出请使用docx格式");
|
||||||
|
if (!saveDir.endsWith("/")) {
|
||||||
|
saveDir = saveDir + File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
File dir = new File(saveDir);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkdirs();
|
||||||
|
}
|
||||||
|
String savePath = saveDir + fileName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
XWPFDocument doc = WordExportUtil.exportWord07(templatePath, params);
|
||||||
|
FileOutputStream fos = new FileOutputStream(savePath);
|
||||||
|
doc.write(fos);
|
||||||
|
fos.flush();
|
||||||
|
fos.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return savePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue