pull/123/head
dxfeng 2 years ago
commit 4d43e0605b

@ -19,11 +19,13 @@ import java.util.Base64;
*/
@Data
public class PersonnelResumePO {
private Integer id;
private String lastName;
private String sex;
private String birthday;
// resourceImageId;
private String image;
private String imageId;
private String nativePlace;
// policy;
private String politics;

@ -23,6 +23,8 @@ public interface HrmResourceMapper {
PersonnelResumePO getPersonnelResumeById(@Param("id") Integer id);
List<PersonnelResumePO> getPersonnelResumeList();
List<HrmFamilyInfoPO> getHrmFamilyInfoByUser(@Param("resourceId") Integer resourceId);
/**

@ -56,6 +56,30 @@
inner join hrmjobtitles b on b.id = h.jobtitle
where h.id = #{id}
</select>
<select id="getPersonnelResumeList"
resultType="com.engine.organization.entity.resume.po.PersonnelResumePO">
select h.id,
lastname,
sex,
birthday,
resourceimageid as image,
resourceimageid as imageId,
nativeplace,
policy as politics,
a.departmentname as department,
maritalstatus as marriage,
b.jobtitlename as jobTitle,
companystartdate,
workstartdate,
certificatenum as idCard,
residentplace as address,
mobile as telephone,
email
from hrmresource h
inner join hrmdepartment a on a.id = h.departmentid
inner join hrmjobtitles b on b.id = h.jobtitle
where h.status &lt; 4
</select>
<select id="getHrmFamilyInfoByUser" resultType="com.engine.organization.entity.resume.po.HrmFamilyInfoPO">
select *
from HrmFamilyInfo

@ -3,6 +3,7 @@ package com.engine.organization.service;
import com.api.browser.bean.SearchConditionItem;
import com.engine.organization.entity.searchtree.SearchTreeParams;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@ -35,5 +36,15 @@ public interface PersonnelResumeService {
*/
Map<String, Object> hasRight();
/**
*
* @param type
* @param response
* @return
*/
String downloadPerResume(Integer type, HttpServletResponse response) throws Exception;
List<SearchConditionItem> personnelScreening();
}

@ -30,12 +30,26 @@ 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 com.engine.organization.util.word.CustomXWPFDocument;
import com.engine.organization.util.word.WordUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.xwpf.usermodel.Document;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPictureData;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import weaver.general.GCONST;
import weaver.general.StringUtil;
import weaver.general.Util;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @author:dxfeng
@ -99,6 +113,112 @@ public class PersonnelResumeServiceImpl extends Service implements PersonnelResu
resultMap.put("selfStatement", "");
// 简历相关表格,待拓展
resultMap.put("tables", getPersonnelResumeTable(uId));
return resultMap;
}
@Override
public Map<String, Object> hasRight() {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("hasRight", true);
ArrayList<MenuBtn> topMenuList = new ArrayList<>();
ArrayList<MenuBtn> rightMenuList = new ArrayList<>();
// 新增
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("screening").menuIcon("icon-coms-man").menuName("人员筛选").type("BTN_Screening").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("currentExport").menuIcon("icon-coms-export").menuName("导出当前").type("BTN_CurrentExport").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("MergeExport").menuIcon("icon-coms02-coms2-Batch-export").menuName("全部导出(合并)").type("BTN_MergeExport").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("AllExport").menuIcon("icon-coms02-coms2-export").menuName("全部导出").type("BTN_AllExport").build());
resultMap.put("topMenu", topMenuList);
// 新增
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("screening").menuIcon("icon-coms-man").menuName("人员筛选").type("BTN_Screening").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("currentExport").menuIcon("icon-coms-export").menuName("导出当前").type("BTN_CurrentExport").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("MergeExport").menuIcon("icon-coms02-coms2-Batch-export").menuName("全部导出(合并)").type("BTN_MergeExport").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("AllExport").menuIcon("icon-coms02-coms2-export").menuName("全部导出").type("BTN_AllExport").build());
resultMap.put("rightMenu", rightMenuList);
return resultMap;
}
@Override
public String downloadPerResume(Integer type, HttpServletResponse response) throws Exception {
//首先定义一个XWPFDocument 集合 这个对象可以进行word 解析 合并 还有下载都离不开这个对象
List<CustomXWPFDocument> xwpfDocuments = new ArrayList<>();
//模板地址
String outPutPath = GCONST.getRootPath() + "hrm" + File.separator + "import" + File.separator + "template" + File.separator;
String filePath = outPutPath + "PerResume.docx";
//创建压缩包位置
File fileZip = new File(outPutPath + "wordZip");
if (!fileZip.exists()) {
fileZip.mkdirs();
}
// 处理赋值的数据
List<Map<String, Object>> dataMapList = getAllResumeList();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
String filesPath = outPutPath + "wordZip" + File.separator + "全部简历";
String fileAllWordPath = outPutPath + "wordZip";
String wordName = "全体人员简历(合并)";
File files = new File(filesPath);
if (!files.exists()) {
files.mkdirs();
} else {
delFolder(files.getPath());
files.mkdirs();
}
//处理所有数据
for (int count = 0; count < dataMapList.size(); count++) {
//处理单人数据
Map<String, Object> paramMap = new HashMap<>();
paramMap = dataMapList.get(count);
WordUtil wordUtil = new WordUtil();
//返回一个新的xwpfDocument对象
File file = new File(filePath);
CustomXWPFDocument doc = null;
InputStream is = new FileInputStream(file);
doc = new CustomXWPFDocument(is);
wordUtil.replaceInPara(doc, paramMap);
wordUtil.replaceInTable(doc, paramMap);
xwpfDocuments.add(doc);
is.close();
String fileName = paramMap.get("${lastName}") + ".docx";
System.out.println(fileName);
FileOutputStream os = null;
os = new FileOutputStream(filesPath + File.separator + new File(fileName));
doc.write(os);
}
if (xwpfDocuments.size() > 0) {
//这样第一步将所有word内容替换之后生成多个 xwpfDocument
//现在将多个xwpfDocument 进行合并 追加 生成word文件
CustomXWPFDocument xwpfDocument = xwpfDocuments.get(0);
for (int i = 0; i < xwpfDocuments.size(); i++) {
//每次的追加为了避免样式和格式混乱 加上分页符
//当是只有一条数据的时候 直接输出
if (i == 0) {
xwpfDocument = xwpfDocuments.get(0);
xwpfDocument.write(new FileOutputStream(fileAllWordPath + File.separator + new File(wordName + ".docx")));
continue;
} else {
//当存在多条时候
xwpfDocument = mergeWord(xwpfDocument, xwpfDocuments.get(i));
xwpfDocument.write(new FileOutputStream(fileAllWordPath + File.separator + new File(wordName + ".docx")));
}
}
}
String resPath = fileAllWordPath + File.separator + new File(wordName + ".docx");
if (type == 1) {
compressFileToZip(filesPath);
resPath = filesPath + ".zip";
}
return resPath;
}
// 简历相关表格,待拓展
public List<PersonnelResumeTable> getPersonnelResumeTable(Integer uId){
List<PersonnelResumeTable> tables = new ArrayList<>();
List<PersonnelResumeColumn> insurancesTitles = new ArrayList<>();
List<PersonnelResumeColumn> familyInfoTitles = new ArrayList<>();
@ -142,34 +262,221 @@ public class PersonnelResumeServiceImpl extends Service implements PersonnelResu
objects.add(familyInfoDatas);
}
tables.add(PersonnelResumeTable.builder().title("三、家庭成员信息(包括父母、配偶、子女)").columns(familyInfoTitles).datas(objects).build());
return tables;
}
public List<Map<String, Object>> getAllResumeList() {
List<PersonnelResumePO> personnelResumeList = getHrmResourceMapper().getPersonnelResumeList();
OrganizationAssert.notNull(personnelResumeList, "未找到对应人员");
List<Map<String, Object>> dataMapList = new ArrayList<>();
for (PersonnelResumePO personnelResumePO : personnelResumeList) {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("${lastName}", Util.null2String(personnelResumePO.getLastName()));
resultMap.put("${sex}", Util.null2String(personnelResumePO.getSex()));
resultMap.put("${birthday}", Util.null2String(personnelResumePO.getBirthday()));
resultMap.put("${@image}", Util.null2String(personnelResumePO.getImageId()));
resultMap.put("${native}", Util.null2String(personnelResumePO.getNativePlace()));
resultMap.put("${politics}", Util.null2String(personnelResumePO.getPolitics()));
resultMap.put("${department}", Util.null2String(personnelResumePO.getDepartment()));
resultMap.put("${marriage}", Util.null2String(personnelResumePO.getMarriage()));
resultMap.put("${jobtitle}", Util.null2String(personnelResumePO.getJobTitle()));
resultMap.put("${companystartdate}", Util.null2String(personnelResumePO.getCompanyStartDate()));
resultMap.put("${workstartdate}", Util.null2String(personnelResumePO.getWorkStartDate()));
resultMap.put("${idCard}", Util.null2String(personnelResumePO.getIdCard()));
resultMap.put("${address}", Util.null2String(personnelResumePO.getAddress()));
resultMap.put("${telephone}", Util.null2String(personnelResumePO.getTelephone()));
resultMap.put("${email}", Util.null2String(personnelResumePO.getEmail()));
resultMap.put("${selfStatement}", "");
List<PersonnelResumeTable> tables = getPersonnelResumeTable(personnelResumePO.getId());
for (int t = 0; t < tables.size(); t++) {
PersonnelResumeTable personnelResumeTable = tables.get(t);
int length = personnelResumeTable.getColumns().size();
if (personnelResumeTable.getDatas().size() > 0) {
List<List<PersonnelResumeColumn>> datas = personnelResumeTable.getDatas();
if (datas.size() > 0) {
List<PersonnelResumeColumn> dataList = datas.get(0);
for (int i = 0; i < length; i++) {
resultMap.put("${col" + t + i + "}", Util.null2String(dataList.get(i).getValue()));
}
}
}
}
dataMapList.add(resultMap);
}
resultMap.put("tables", tables);
return dataMapList;
}
return resultMap;
//两个对象进行追加
public CustomXWPFDocument mergeWord(CustomXWPFDocument document, CustomXWPFDocument doucDocument2) throws Exception {
CustomXWPFDocument src1Document = document;
XWPFParagraph p = src1Document.createParagraph();
//设置分页符
p.setPageBreak(true);
CTBody src1Body = src1Document.getDocument().getBody();
CustomXWPFDocument src2Document = doucDocument2;
CTBody src2Body = src2Document.getDocument().getBody();
XWPFParagraph p2 = src2Document.createParagraph();
//处理合并后文档图片冲突
List<XWPFPictureData> allPictures = src2Document.getAllPictures();
Map<String, String> map = new HashMap();
for (XWPFPictureData picture : allPictures) {
String before = src2Document.getRelationId(picture);
//将原文档中的图片加入到目标文档中
String after = src1Document.addPictureData(picture.getData(), Document.PICTURE_TYPE_JPEG);
map.put(before, after);
}
XmlOptions optionsOuter = new XmlOptions();
optionsOuter.setSaveOuter();
String appendString = src2Body.xmlText(optionsOuter);
String srcString = src1Body.xmlText();
String prefix = srcString.substring(0, srcString.indexOf(">") + 1);
String mainPart = srcString.substring(srcString.indexOf(">") + 1, srcString.lastIndexOf("<"));
String sufix = srcString.substring(srcString.lastIndexOf("<"));
String addPart = appendString.substring(appendString.indexOf(">") + 1, appendString.lastIndexOf("<"));
if (map != null && !map.isEmpty()) {
ListIterator<Map.Entry<String, String>> i = new ArrayList<>(map.entrySet()).listIterator(map.size());
LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
while (i.hasPrevious()) {
Map.Entry<String, String> entry = i.previous();
linkedHashMap.put(entry.getKey(), entry.getValue());
}
Iterator it1 = linkedHashMap.entrySet().iterator();
while (it1.hasNext()) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) it1.next();
addPart = addPart.replace("<a:blip r:embed=\"" + entry.getKey(), "<a:blip r:embed=\"" + entry.getValue());
}
}
CTBody makeBody = CTBody.Factory.parse(prefix + mainPart + addPart + sufix);
src1Body.set(makeBody);
return src1Document;
}
@Override
public Map<String, Object> hasRight() {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("hasRight", true);
ArrayList<MenuBtn> topMenuList = new ArrayList<>();
ArrayList<MenuBtn> rightMenuList = new ArrayList<>();
// 新增
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("screening").menuIcon("icon-coms-man").menuName("人员筛选").type("BTN_Screening").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("currentExport").menuIcon("icon-coms-export").menuName("导出当前").type("BTN_CurrentExport").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("mergeExport").menuIcon("icon-coms02-coms2-Batch-export").menuName("全部导出(合并)").type("BTN_MergeExport").build());
topMenuList.add(MenuBtn.builder().isBatch("0").isTop("1").menuFun("allExport").menuIcon("icon-coms02-coms2-export").menuName("全部导出").type("BTN_AllExport").build());
/**
* @Title: compressAllFileZip
* @Description:
* @param @param compresspath
* @return void
* @throws
*/
public static boolean compressFileToZip(String compresspath) {
boolean bool = false;
try {
ZipOutputStream zipOutput = null;
File file = new File(compresspath);
if (file.isDirectory()) {
zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(compresspath + ".zip")));
compressZip(zipOutput, file, "");
} else {
zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(compresspath.substring(0, compresspath.lastIndexOf(".")) + ".zip")));
}
zipOutput.closeEntry();
zipOutput.close();
bool = true;
} catch (Exception e) {
e.printStackTrace();
}
return bool;
}
resultMap.put("topMenu", topMenuList);
// 新增
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("screening").menuIcon("icon-coms-man").menuName("人员筛选").type("BTN_Screening").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("currentExport").menuIcon("icon-coms-export").menuName("导出当前").type("BTN_CurrentExport").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("mergeExport").menuIcon("icon-coms02-coms2-Batch-export").menuName("全部导出(合并)").type("BTN_MergeExport").build());
rightMenuList.add(MenuBtn.builder().isBatch("0").isTop("0").menuFun("allExport").menuIcon("icon-coms02-coms2-export").menuName("全部导出").type("BTN_AllExport").build());
/**
* @Title: compressZip
* @Description:
* @param @param zipOutput
* @param @param file
* @param @param suffixpath
* @param @throws IOException
* @return void
* @throws
*/
private static void compressZip(ZipOutputStream zipOutput, File file, String suffixpath) {
File[] listFiles = file.listFiles();// 列出所有的文件
for (File fi : listFiles) {
if (fi.isDirectory()) {
if (suffixpath.equals("")) {
compressZip(zipOutput, fi, fi.getName());
} else {
compressZip(zipOutput, fi, suffixpath + File.separator + fi.getName());
}
} else {
zip(zipOutput, fi, suffixpath);
}
}
}
resultMap.put("rightMenu", rightMenuList);
return resultMap;
public static void zip(ZipOutputStream zipOutput, File file, String suffixpath) {
try {
ZipEntry zEntry = null;
if (suffixpath.equals("")) {
zEntry = new ZipEntry(file.getName());
} else {
zEntry = new ZipEntry(suffixpath + File.separator + file.getName());
}
zipOutput.putNextEntry(zEntry);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[1024];
int read = 0;
while ((read = bis.read(buffer)) != -1) {
zipOutput.write(buffer, 0, read);
}
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/***
*
*
* @param folderPath
*/
public static void delFolder(String folderPath) {
try {
delAllFile(folderPath); // 删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); // 删除空文件夹
} catch (Exception e) {
e.printStackTrace();
}
}
/***
*
*
* @param path
* @return
*/
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
return flag;
}
if (!file.isDirectory()) {
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
temp.delete();
}
if (temp.isDirectory()) {
delAllFile(path + "/" + tempList[i]);// 先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);// 再删除空文件夹
flag = true;
}
}
return flag;
}
@Override
@ -298,7 +605,6 @@ public class PersonnelResumeServiceImpl extends Service implements PersonnelResu
}
if (CollectionUtils.isNotEmpty(departmentsByIds)) {
departmentsByIds.removeIf(item -> item.getCanceled() != null && item.getCanceled() != 0);
filterDeparts.addAll(departmentsByIds);
}
}
@ -395,6 +701,7 @@ public class PersonnelResumeServiceImpl extends Service implements PersonnelResu
return SearchTreeUtil.builderTreeMode(DepartmentBO.buildSetToSearchTree(builderDeparts), jobTrees);
}
/**
*
*

@ -0,0 +1,144 @@
package com.engine.organization.util.word;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlToken;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
import java.io.IOException;
import java.io.InputStream;
public class CustomXWPFDocument extends XWPFDocument {
public CustomXWPFDocument(InputStream in) throws IOException {
super(in);
}
public CustomXWPFDocument() {
super();
}
public CustomXWPFDocument(OPCPackage pkg) throws IOException {
super(pkg);
}
/**
* @param id
* @param width
* @param height
* @param paragraph
*/
public void createPicture(String blipId,int id, int width, int height, XWPFParagraph paragraph, CustomXWPFDocument doc) {
final int EMU = 9525;
width *= EMU;
height *= EMU;
CTInline inline = paragraph.createRun().getCTR().addNewDrawing().addNewInline();
String picXml = ""
+ "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
+ " <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"
+ " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"
+ " <pic:nvPicPr>" + " <pic:cNvPr id=\""
+ id
+ "\" name=\"Generated\"/>"
+ " <pic:cNvPicPr/>"
+ " </pic:nvPicPr>"
+ " <pic:blipFill>"
+ " <a:blip r:embed=\""
+ blipId
+ "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>"
+ " <a:stretch>"
+ " <a:fillRect/>"
+ " </a:stretch>"
+ " </pic:blipFill>"
+ " <pic:spPr>"
+ " <a:xfrm>"
+ " <a:off x=\"0\" y=\"0\"/>"
+ " <a:ext cx=\""
+ width
+ "\" cy=\""
+ height
+ "\"/>"
+ " </a:xfrm>"
+ " <a:prstGeom prst=\"rect\">"
+ " <a:avLst/>"
+ " </a:prstGeom>"
+ " </pic:spPr>"
+ " </pic:pic>"
+ " </a:graphicData>" + "</a:graphic>";
inline.addNewGraphic().addNewGraphicData();
XmlToken xmlToken = null;
try {
xmlToken = XmlToken.Factory.parse(picXml);
} catch (XmlException xe) {
xe.printStackTrace();
}
inline.set(xmlToken);
CTPositiveSize2D extent = inline.addNewExtent();
extent.setCx(width);
extent.setCy(height);
CTNonVisualDrawingProps docPr = inline.addNewDocPr();
docPr.setId(id);
docPr.setName("图片" + blipId);
docPr.setDescr("头像");
}
public void createPicture(String blipId, int id, int width, int height, XWPFParagraph paragraph) {
final int EMU = 9525;
width *= EMU;
height *= EMU;
//String blipId = getAllPictures().get(id).getPackageRelationship().getId();
CTInline inline = paragraph.createRun().getCTR().addNewDrawing().addNewInline();
String picXml = "" +
"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" +
" <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" +
" <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" +
" <pic:nvPicPr>" +
" <pic:cNvPr id=\"" + id + "\" name=\"Generated\"/>" +
" <pic:cNvPicPr/>" +
" </pic:nvPicPr>" +
" <pic:blipFill>" +
" <a:blip r:embed=\"" + blipId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" +
" <a:stretch>" +
" <a:fillRect/>" +
" </a:stretch>" +
" </pic:blipFill>" +
" <pic:spPr>" +
" <a:xfrm>" +
" <a:off x=\"0\" y=\"0\"/>" +
" <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" +
" </a:xfrm>" +
" <a:prstGeom prst=\"rect\">" +
" <a:avLst/>" +
" </a:prstGeom>" +
" </pic:spPr>" +
" </pic:pic>" +
" </a:graphicData>" +
"</a:graphic>";
inline.addNewGraphic().addNewGraphicData();
XmlToken xmlToken = null;
try {
xmlToken = XmlToken.Factory.parse(picXml);
} catch (XmlException xe) {
xe.printStackTrace();
}
inline.set(xmlToken);
CTPositiveSize2D extent = inline.addNewExtent();
extent.setCx(width);
extent.setCy(height);
CTNonVisualDrawingProps docPr = inline.addNewDocPr();
docPr.setId(id);
docPr.setName("图片" + id);
docPr.setDescr("头像");
}
}

@ -0,0 +1,274 @@
package com.engine.organization.util.word;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
import weaver.file.ImageFileManager;
import weaver.general.Util;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WordUtil {
/**
*
*
* @param doc
* @param params
* @throws FileNotFoundException
* @throws InvalidFormatException
*/
public void replaceInPara(CustomXWPFDocument doc, Map<String, Object> params) throws InvalidFormatException, FileNotFoundException {
Iterator<XWPFParagraph> iterator = doc.getParagraphsIterator();
XWPFParagraph para;
while (iterator.hasNext()) {
para = iterator.next();
this.replaceInPara(para, params,doc);
}
}
/**
*
*
* @param para
* @param params
* @throws FileNotFoundException
* @throws InvalidFormatException
*/
public void replaceInPara(XWPFParagraph para, Map<String, Object> params, CustomXWPFDocument doc) throws InvalidFormatException, FileNotFoundException {
List<XWPFRun> runs;
Matcher matcher;
if (this.matcher(para.getParagraphText()).find()) {
runs = para.getRuns();
int start = -1;
int end = -1;
String str = "";
String text= "";
for (int i = 0; i < runs.size(); i++) {
text += runs.get(i).toString();
}
for (int i = 0; i < runs.size(); i++) {
XWPFRun run = runs.get(i);
// System.out.println("------>>>>>>>>>" + text);
if (text.contains("$")) {
start = text.indexOf("$");
}
if ((start != -1)) {
str += text.substring(text.indexOf("$"), text.length()).trim();
String paraList=runs.toString();
// System.out.println("未删除前"+paraList);
Object[] runArr = runs.toArray();
int size=runs.size();
int $Index=0;
for (int j = 0; j < runArr.length; j++) {
if (runArr[j].toString().contains("$")) {
$Index=j;
break;
}
}
int startIn=$Index;
while (startIn<runs.size()) {
para.removeRun(startIn);
// System.out.println("删除中"+para.getRuns());
}
// System.out.println("删除后"+para.getRuns());
}
if ('}' == text.charAt(text.length() - 1)) {
if (start != -1) {
end = text.length() - 1;
break;
}
}
}
// System.out.println("start--->"+start);
// System.out.println("end--->"+end);
// System.out.println("str---->>>" + str);
for (String key : params.keySet()) {
if (str.equals(key)) {
if(str.indexOf("@")==-1){
String value= params.get(key).toString();
para.createRun().setText(value);
break;
}else{
String value= params.get(key).toString();
if (StringUtils.isBlank(value)){
break;
}
int length = para.getRuns().size();
if (length > 0) {
for (int i = (length - 1); i >= 0; i--) {
para.removeRun(i);
}
}
//网络图片取文件数据
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(Util.getIntValue(value));
InputStream inputStream = manager.getInputStream();
byte[] buff = new byte[8000];
int bytesRead = 0;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
while(true) {
try {
if (!((bytesRead = inputStream.read(buff)) != -1)) break;
} catch (IOException e) {
e.printStackTrace();
}
bao.write(buff, 0, bytesRead);
}
byte[] data = bao.toByteArray();
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(data);
String blipId = doc.addPictureData(byteInputStream, CustomXWPFDocument.PICTURE_TYPE_PNG);
doc.createPicture(blipId,doc.getNextPicNameNumber(CustomXWPFDocument.PICTURE_TYPE_PNG), 120, 180,para);
break;
}
}
}
}
}
/**
*
*
* @param doc
* @param params
* @throws FileNotFoundException
* @throws InvalidFormatException
*/
public void replaceInTable(CustomXWPFDocument doc, Map<String, Object> params) throws InvalidFormatException, FileNotFoundException {
Iterator<XWPFTable> iterator = doc.getTablesIterator();
XWPFTable table;
List<XWPFTableRow> rows;
List<XWPFTableCell> cells;
List<XWPFParagraph> paras;
while (iterator.hasNext()) {
table = iterator.next();
rows = table.getRows();
for (XWPFTableRow row : rows) {
cells = row.getTableCells();
for (XWPFTableCell cell : cells) {
paras = cell.getParagraphs();
for (XWPFParagraph para : paras) {
this.replaceInPara(para, params,doc);
}
}
}
}
}
/**
*
*
* @param str
* @return
*/
private Matcher matcher(String str) {
Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
return matcher;
}
/**
*
*
* @param is
*/
public void close(InputStream is) {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
*
* @param os
*/
public void close(OutputStream os) {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* :线
*
* @param strUrl
* @return
* @see [/]()
* @since [/]()
*/
public static byte[] getImageData(String strUrl) {
InputStream inStream = null;
try {
// new一个URL对象
URL url = new URL(strUrl);
// 打开链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置请求方式为"GET"
conn.setRequestMethod("GET");
// 超时响应时间为5秒
conn.setConnectTimeout(10 * 1000);
// 通过输入流获取图片数据
inStream = conn.getInputStream();
byte[] data = readInputStream(inStream);
return data;
} catch (Exception e) {
return null;
} finally {
if (inStream != null) {
try {
inStream.close();
} catch (Exception e2) {
System.out.println("关闭流失败");
}
}
}
}
/**
* :
*
* @param inStream
* @return
* @throws Exception
* @see [/]()
* @since [/]()
*/
public static byte[] readInputStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// 创建一个Buffer字符串
byte[] buffer = new byte[1024];
// 每次读取的字符串长度,如果为-1代表全部读取完毕
int len = 0;
// 使用一个输入流从buffer里把数据读取出来
while ((len = inStream.read(buffer)) != -1) {
// 用输出流往buffer里写入数据中间参数代表从哪个位置开始读len代表读取的长度
outStream.write(buffer, 0, len);
}
// 关闭输入流
inStream.close();
// 把outStream里的数据写入内存
return outStream.toByteArray();
}
}

@ -22,6 +22,9 @@ import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.ws.rs.core.Response;
import java.io.*;
import java.net.URLEncoder;
import java.util.Map;
/**
@ -96,4 +99,32 @@ public class PersonnelResumeController {
}
/**
*
*
* @param request
* @param response
* @return
*/
@GET
@Path("/downloadPerResume")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadPerResume(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> map = ParamUtil.request2Map(request);
// type: 0:合并 1不合并
Integer type = Integer.parseInt(Util.null2String(map.get("type")));
String realPath = getPersonnelResumeWrapper(user).downloadPerResume(type,response);
File file = new File(realPath);
// 如果文件不存在提示404
if (!file.exists()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
String fileName = URLEncoder.encode(file.getName(), "UTF-8");
return Response
.ok(file)
.header("Content-disposition", "attachment;filename=" + fileName)
.header("Cache-Control", "no-cache").build();
}
}

@ -6,9 +6,11 @@ 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.List;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
@ -33,6 +35,10 @@ public class PersonnelResumeWrapper extends OrganizationWrapper {
return getPersonnelResumeService(user).getResumeList(uId);
}
public String downloadPerResume(Integer type, HttpServletResponse response) throws Exception {
return getPersonnelResumeService(user).downloadPerResume(type, response);
}
public List<SearchConditionItem> personnelScreening() {
return getPersonnelResumeService(user).personnelScreening();
}

Loading…
Cancel
Save