人员简历模板导出
This commit is contained in:
parent
76f1501a28
commit
bc47f697d0
|
|
@ -24,4 +24,13 @@ public interface PersonnelResumeService {
|
|||
* @return
|
||||
*/
|
||||
Map<String, Object> hasRight();
|
||||
|
||||
|
||||
/**
|
||||
* 人员简历下载
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> downloadPerResume(SearchTreeParams params);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,20 @@ import com.engine.organization.mapper.job.JobMapper;
|
|||
import com.engine.organization.mapper.resource.HrmResourceMapper;
|
||||
import com.engine.organization.service.PersonnelResumeService;
|
||||
import com.engine.organization.util.MenuBtn;
|
||||
import com.engine.organization.util.WordUtil;
|
||||
import com.engine.organization.util.WordUtils;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import com.engine.organization.util.detach.DetachUtil;
|
||||
import com.engine.organization.util.page.PageUtil;
|
||||
import com.engine.organization.util.tree.SearchTreeUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import weaver.general.GCONST;
|
||||
import weaver.general.StringUtil;
|
||||
import weaver.general.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -86,6 +92,62 @@ public class PersonnelResumeServiceImpl extends Service implements PersonnelResu
|
|||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> downloadPerResume(SearchTreeParams params) {
|
||||
// 调用word文档帮助类
|
||||
WordUtil wordUtil = new WordUtil();
|
||||
|
||||
// 模板文件存放的目录
|
||||
wordUtil.setBaseDir("E:/ww");
|
||||
|
||||
// 模板文件名称
|
||||
wordUtil.setTemplateFile("template.ftl");
|
||||
|
||||
// word生成的输出目录
|
||||
wordUtil.setOutputDir("E:/image/");
|
||||
|
||||
// 初始化数据map
|
||||
Map<String,Object> dataMap = new HashMap<>();
|
||||
|
||||
// 录入采购基本数据
|
||||
dataMap.put("data1", "XX公司");
|
||||
dataMap.put("data2", "XX项目");
|
||||
dataMap.put("data3", "2022.01.01");
|
||||
dataMap.put("data4", "采购部");
|
||||
dataMap.put("data5", "张三");
|
||||
dataMap.put("data6", "189XXXXXXX");
|
||||
dataMap.put("data7", "李四");
|
||||
dataMap.put("data8", "张主任");
|
||||
dataMap.put("data9", "王总");
|
||||
dataMap.put("data10", "王某");
|
||||
dataMap.put("data11", "王某");
|
||||
dataMap.put("data12", "张三");
|
||||
|
||||
|
||||
// 录入表格数据(3条数据循环三次)
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
dataMap.put("dataName"+i, "笔记本电脑"+i);
|
||||
dataMap.put("dataBand"+i, "金山牌"+i);
|
||||
dataMap.put("model"+i, "JHHJ6"+i);
|
||||
dataMap.put("price"+i, 5000+i);
|
||||
dataMap.put("quantity"+i, 3+i);
|
||||
dataMap.put("total"+i, 15000+i);
|
||||
}
|
||||
|
||||
//处理定价方式复选框
|
||||
dataMap.put("select", "☑境内采购" + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + "□境外采购");
|
||||
|
||||
String oldPath = wordUtil.createWord(dataMap);
|
||||
|
||||
if (oldPath.equals("操作失败")){
|
||||
System.out.println("操作失败");
|
||||
}
|
||||
|
||||
//输出生成后的文件路径
|
||||
System.out.println(oldPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SearchTree> getFilterDatas(String id, String type, String keyword) {
|
||||
List<SearchTree> searchTree = new ArrayList<>();
|
||||
// 通过分部、公司 组装数据
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
package com.engine.organization.util;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @date
|
||||
* @apiNote 生成动态文档帮助类
|
||||
*/
|
||||
@Data
|
||||
public class WordUtil {
|
||||
private Configuration configuration = null;
|
||||
|
||||
/*
|
||||
* 模板文件存放的目录
|
||||
*/
|
||||
private String baseDir;
|
||||
|
||||
/*
|
||||
* 模板文件名称
|
||||
*/
|
||||
private String templateFile;
|
||||
|
||||
/*
|
||||
* word生成的输出目录
|
||||
*/
|
||||
private String outputDir;
|
||||
|
||||
public WordUtil(){
|
||||
configuration = new Configuration();
|
||||
configuration.setDefaultEncoding("utf-8");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* <p>转换成word<br>
|
||||
*/
|
||||
public String createWord(Map<String,Object> dataMap){
|
||||
|
||||
configuration.setClassForTemplateLoading(this.getClass(), "");//模板文件所在路径
|
||||
|
||||
Template t = null;
|
||||
|
||||
try {
|
||||
//得到模板文件
|
||||
configuration.setDirectoryForTemplateLoading(new File(baseDir));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
t = configuration.getTemplate(templateFile,"utf-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// GwUtil.getFileNo(""); 调用生成随机数的方法
|
||||
File outFile = new File(outputDir + "222.doc"); //导出文件
|
||||
|
||||
Writer out = null;
|
||||
try {
|
||||
try {
|
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"utf-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
t.process(dataMap, out); //将填充数据填入模板文件并输出到目标文件
|
||||
return outFile.getPath();
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "文档生成失败";
|
||||
}
|
||||
}
|
||||
|
|
@ -59,4 +59,20 @@ public class PersonnelResumeController {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧树接口
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Path("/downloadPerResume")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Map<String, Object> downloadPerResume(@Context HttpServletRequest request, @Context HttpServletResponse response){
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||
SearchTreeParams params = JSONObject.toJavaObject((JSON) JSONObject.toJSON(map), SearchTreeParams.class);
|
||||
return getPersonnelResumeWrapper(user).downloadPerResume(params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.engine.organization.entity.searchtree.SearchTreeParams;
|
|||
import com.engine.organization.service.PersonnelResumeService;
|
||||
import com.engine.organization.service.impl.PersonnelResumeServiceImpl;
|
||||
import com.engine.organization.util.OrganizationWrapper;
|
||||
import tebie.applib.api.O;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -26,4 +27,8 @@ public class PersonnelResumeWrapper extends OrganizationWrapper {
|
|||
public Map<String, Object> hasRight() {
|
||||
return getPersonnelResumeService(user).hasRight();
|
||||
}
|
||||
|
||||
public Map<String, Object> downloadPerResume(SearchTreeParams params) {
|
||||
return getPersonnelResumeService(user).downloadPerResume(params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue