feat: 流程入库 及 杂七杂八

This commit is contained in:
super_liu
2021-06-21 18:36:52 +08:00
parent 3f79fe9df6
commit c3f912eefb
39 changed files with 3284 additions and 11 deletions
@@ -0,0 +1,283 @@
package com.adc.da.common;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import java.util.ArrayList;
import java.util.List;
/**
* @Description:
* @Author: yangxuenan
* date: 2020/2/26 10:10
*/
public class ConvertHtml2Excel {
/**
* html表格转excel
*/
public static HSSFWorkbook table2Excel(String tableHtml, HSSFWorkbook wb, String sheetName) throws Exception {
// HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(sheetName);
List<Integer> moneyCols =new ArrayList<>();
moneyCols.add(1);
int headEndRow = 1;
List<CrossRangeCellMeta> crossRowEleMetaLs = new ArrayList<CrossRangeCellMeta>();
int rowIndex = 0;
try {
Document data = DocumentHelper.parseText(tableHtml);
HSSFCellStyle contentStyle = getContentStyle(wb);
// 生成表头
Element thead = data.getRootElement().element("thead");
HSSFCellStyle titleStyle = getTitleStyle(wb);
int ls = 0;//列数
if (thead != null) {
List<Element> trLs = thead.elements("tr");
for (Element trEle : trLs) {
HSSFCellStyle style = rowIndex<=headEndRow?titleStyle:contentStyle;
style.setWrapText(true);
HSSFRow row = sheet.createRow(rowIndex);
List<Element> thLs = trEle.elements("th");
if(ls<thLs.size())
ls = thLs.size();
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, style, crossRowEleMetaLs, true,moneyCols);
List<Element> tdLs = trEle.elements("td");
if(ls<ls+tdLs.size())
ls = ls + tdLs.size();
makeRowCell(tdLs, rowIndex, row, cellIndex, style, crossRowEleMetaLs, true,moneyCols);
rowIndex++;
}
}
// 生成表体
Element tbody = data.getRootElement().element("tbody");
if (tbody != null) {
List<Element> trBody = tbody.elements("tr");
for (Element trEle : trBody) {
HSSFCellStyle style = rowIndex<=headEndRow?titleStyle:contentStyle;
style.setWrapText(true);
HSSFRow row = sheet.createRow(rowIndex);
List<Element> thLs = trEle.elements("th");
if(ls<thLs.size())
ls = thLs.size();
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, style, crossRowEleMetaLs, false,moneyCols);
List<Element> tdLs = trEle.elements("td");
if(ls<ls+tdLs.size())
ls = ls + tdLs.size();
makeRowCell(tdLs, rowIndex, row, cellIndex, style, crossRowEleMetaLs, false,moneyCols);
rowIndex++;
}
}
// 生成表体
Element tfoot = data.getRootElement().element("tfoot");
if (tfoot != null) {
List<Element> trFoot = tfoot.elements("tr");
for (Element trEle : trFoot) {
HSSFCellStyle style = rowIndex<=headEndRow?titleStyle:contentStyle;
style.setWrapText(true);
HSSFRow row = sheet.createRow(rowIndex);
List<Element> thLs = trEle.elements("th");
if(ls<thLs.size())
ls = thLs.size();
int cellIndex = makeRowCell(thLs, rowIndex, row, 0, style, crossRowEleMetaLs, false,moneyCols);
List<Element> tdLs = trEle.elements("td");
if(ls<ls+tdLs.size())
ls = ls + tdLs.size();
makeRowCell(tdLs, rowIndex, row, cellIndex, style, crossRowEleMetaLs, false,moneyCols);
rowIndex++;
}
}
// 合并表头
for (CrossRangeCellMeta crcm : crossRowEleMetaLs) {
sheet.addMergedRegion(new CellRangeAddress(crcm.getFirstRow(), crcm.getLastRow(), crcm.getFirstCol(), crcm.getLastCol()));
HSSFCellStyle mergeStyle;
if (crcm.isInHead()) {
mergeStyle = titleStyle;
} else {
mergeStyle = contentStyle;
}
mergeStyle.setWrapText(true);
setRegionStyle(sheet, new CellRangeAddress(crcm.getFirstRow(), crcm.getLastRow(), crcm.getFirstCol(), crcm.getLastCol()), mergeStyle);
}
for (int i = 0; i < ls; i++) {
sheet.autoSizeColumn(i, true);//设置列宽
sheet.setColumnWidth(i,30*256);
// sheet.setColumnWidth(i,sheet.getColumnWidth(i)*15/10);
}
} catch (Exception e) {
e.printStackTrace();
}
return wb;
}
/**
* 生产行内容
*
* @return 最后一列的cell index
*/
/**
* @param tdLs th或者td集合
* @param rowIndex 行号
* @param row POI行对象
* @param startCellIndex
* @param cellStyle 样式
* @param crossRowEleMetaLs 跨行元数据集合
* @return
*/
private static int makeRowCell(List<Element> tdLs, int rowIndex, HSSFRow row, int startCellIndex, HSSFCellStyle cellStyle,
List<CrossRangeCellMeta> crossRowEleMetaLs, boolean inHead, List<Integer> moneyCols) {
int i = startCellIndex;
for (int eleIndex = 0; eleIndex < tdLs.size(); i++, eleIndex++) {
int captureCellSize = getCaptureCellSize(rowIndex, i, crossRowEleMetaLs);
while (captureCellSize > 0) {
for (int j = 0; j < captureCellSize; j++) {// 当前行跨列处理(补单元格)
row.createCell(i);
i++;
}
captureCellSize = getCaptureCellSize(rowIndex, i, crossRowEleMetaLs);
}
Element thEle = tdLs.get(eleIndex);
String val = thEle.getText();
if (StringUtils.isEmpty(val)) {
Element e = thEle.element("a");
if (e != null) {
val = e.getText();
}
}
HSSFCell c = row.createCell(i);
if (NumberUtils.isNumber(val)) {
if (moneyCols != null && moneyCols.contains(i)) {
c.setCellType(CellType.STRING);
c.setCellValue(val);
} else {
c.setCellValue(Double.parseDouble(val));
c.setCellType(CellType.STRING);
}
} else {
c.setCellType(CellType.STRING);
c.setCellValue(new HSSFRichTextString(val));
}
int rowSpan = NumberUtils.toInt(thEle.attributeValue("rowspan"), 1);
int colSpan = NumberUtils.toInt(thEle.attributeValue("colspan"), 1);
c.setCellStyle(cellStyle);
if (rowSpan > 1 || colSpan > 1) { // 存在跨行或跨列
crossRowEleMetaLs.add(new CrossRangeCellMeta(rowIndex, i, rowSpan, colSpan, inHead));
}
if (colSpan > 1) {// 当前行跨列处理(补单元格)
for (int j = 1; j < colSpan; j++) {
i++;
row.createCell(i);
}
}
}
return i;
}
/**
* 设置合并单元格的边框样式
*
* @param sheet
* @param region
* @param cs
*/
public static void setRegionStyle(HSSFSheet sheet, CellRangeAddress region, HSSFCellStyle cs) {
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
HSSFRow row = sheet.getRow(i);
for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
HSSFCell cell = row.getCell(j);
cell.setCellStyle(cs);
}
}
}
/**
* 获得因rowSpan占据的单元格
*
* @param rowIndex 行号
* @param colIndex 列号
* @param crossRowEleMetaLs 跨行列元数据
* @return 当前行在某列需要占据单元格
*/
private static int getCaptureCellSize(int rowIndex, int colIndex, List<CrossRangeCellMeta> crossRowEleMetaLs) {
int captureCellSize = 0;
for (CrossRangeCellMeta crossRangeCellMeta : crossRowEleMetaLs) {
if (crossRangeCellMeta.getFirstRow() < rowIndex && crossRangeCellMeta.getLastRow() >= rowIndex) {
if (crossRangeCellMeta.getFirstCol() <= colIndex && crossRangeCellMeta.getLastCol() >= colIndex) {
captureCellSize = crossRangeCellMeta.getLastCol() - colIndex + 1;
}
}
}
return captureCellSize;
}
/**
* 获得标题样式
*
* @param workbook
* @return
*/
private static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
short titlebackgroundcolor = HSSFColor.HSSFColorPredefined.WHITE.getIndex();
short fontSize = 11;
String fontName = "宋体";
HSSFCellStyle style = workbook.createCellStyle();
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setAlignment(HorizontalAlignment.CENTER);
style.setBorderBottom(BorderStyle.THIN); //下边框
style.setBorderLeft(BorderStyle.THIN);//左边框
style.setBorderTop(BorderStyle.THIN);//上边框
style.setBorderRight(BorderStyle.THIN);//右边框
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(titlebackgroundcolor);// 背景色
style.setWrapText(true);
HSSFFont font = workbook.createFont();
// font.setFontName(fontName);
font.setFontHeightInPoints(fontSize);
// font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style.setFont(font);
return style;
}
/**
* 获得内容样式
*
* @param wb
* @return
*/
private static HSSFCellStyle getContentStyle(HSSFWorkbook wb) {
short fontSize = 11;
// String fontName = "宋体";
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
HSSFFont font = wb.createFont();
// font.setFontName(fontName);
font.setFontHeightInPoints(fontSize);
style.setFont(font);
style.setAlignment(HorizontalAlignment.CENTER);//水平居中
style.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
style.setWrapText(true);
return style;
}
public static void main(String[] args) throws Exception {
String cnt = "\n";
List<Integer> c =new ArrayList<>();
c.add(1);
String tableHtml = "<table><tbody><tr><td colspan='2'>11111111</td><td rowspan='3'>3333333333</td><td>444444444</td></tr><tr><td>5555555</td><td>66666</td><td></td></tr><tr><td></td><td>324234</td><td></td></tr></tbody></table>";
tableHtml = tableHtml.replaceAll("<[\\s]*?br[^>]*?>|<[\\s]*?\\/[\\s]*?br[\\s]*?>", cnt);
// HSSFWorkbook hssfWorkbook = ConvertHtml2Excel.table2Excel(tableHtml,c,1);
// hssfWorkbook.write(FileUtils.openOutputStream(new File("D:\\test\\test1.xls")));
}
}
@@ -0,0 +1,39 @@
package com.adc.da.workFlow.controller;
import com.adc.da.base.web.BaseController;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.sarStandardsInfo.entity.ActSarItemsEO;
import com.adc.da.workFlow.service.ActSarItemsEOService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/${restPath}/lawss/actSarItems")
@Api(description = "|ActSarItemsEO|")
public class ActSarItemsEOController extends BaseController<ActSarItemsEO> {
@Autowired
private ActSarItemsEOService actSarItemsEOService;
// private static final Logger logger = LoggerFactory.getLogger(AttFileEOController.class);
@Value("${file.path}")
private String filePath;//文件存储路径
@ApiOperation(value = "|SarStandardsInfoEO|标准入库流程标准入库")
@PostMapping("/processCreateStand")
public ResponseMessage processCreateStand(String infoJson) throws Exception {
if (StringUtils.isNotBlank(infoJson)) {
actSarItemsEOService.processCreateStand(infoJson);
return Result.success("入库成功");
} else {
return Result.error("传入数据json不能为空");
}
}
}
@@ -0,0 +1,16 @@
package com.adc.da.workFlow.dao;
import com.adc.da.slrs.sarStandardsInfo.entity.ActSarItemsEO;
import java.util.List;
public interface ActSarItemsEODao {
List<ActSarItemsEO> queryByPage(ActSarItemsEO actSarItemsEO);
Integer process4PageDateCount(ActSarItemsEO actSarItemsEO);
int queryByCount();
List<ActSarItemsEO> queryStandAndLaws(ActSarItemsEO actSarItemsEO);
}
@@ -0,0 +1,66 @@
package com.adc.da.workFlow.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @Author yangxuenan
* @Description 工作流使用
* Date 2018/10/23 14:29
* @Param
* @return
**/
@Data
public class ActSarItemsEO {
private String resId;// 标准法规ID
private String resFlag; //类型
private String resNum; //标准,文件号
private String resName; //标准,文件名称
private String resType; //标准类型
private String deptName; //部门id
private String orgName; // 责任部门名称
private String parentId; //仅条目有
private String userId; //评估人ID
private List<ActSarItemsEO> itemsList; //条目信息
private String accessId; //导入时查询
private String applyArctic;
private String[] applyArcticList;
private String energyKind;
private String[] energyKindList;
private String mainPointImplementation;
private String termsConditions;
private String parts;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date tackTime;
private String applyArcticShow;
private String energyKindShow;
private String remarks;
private String resState; //标准状态
private String fileState; //文本状态
private String type; //符合性状态
private String prcNum;
private String foId;
private String foName;
private String form;
private String roleId;
private String roleName;
//流程分页用
private Integer startIndex;
private Integer endIndex;
private Integer pageSize;
private Integer nowPage;
private Map<String, Object> attrInfoMap = new LinkedHashMap<>(); //属性表字段与值
private String sarState;
private String newPutText;
private String prodPutText;
private String authObj;
private String authDelive;
private String performInfo;
}