源码补充

main
zhangming 9 months ago
parent da53b73432
commit 44768418b2

@ -0,0 +1,81 @@
package com.engine.kq.biz;
import weaver.cache.CacheBase;
import weaver.cache.CacheColumn;
import weaver.cache.CacheColumnType;
import weaver.cache.PKColumn;
/**
*
*/
public class KQChildrenComInfo extends CacheBase {
/**
*
*/
protected static String TABLE_NAME = "hrmfamilyinfo";
/**
* sqlwherewhere
*/
protected static String TABLE_WHERE = " WhetherChildren=1 ";
/**
* sqlorder byorder by
*/
protected static String TABLE_ORDER = " id ";
/**
*
*/
@PKColumn(type = CacheColumnType.NUMBER)
protected static String PK_NAME = "id";
/**
*
*/
@CacheColumn(name = "birthday")
protected static int birthday;
/**
*
*/
@CacheColumn(name = "member")
protected static int member;
/**
* id
*/
@CacheColumn(name = "resourceid")
protected static int resourceid;
public String getId(){
return (String)getRowValue(PK_INDEX);
}
public String getChildrenName() {
return (String)getRowValue(member);
}
public String getChildrenName(String key){
return (String) getValue(member,key);
}
public String getBirthday() {
return (String)getRowValue(birthday);
}
public String getBirthday(String key){
return (String) getValue(birthday,key);
}
public String getResourceid() {
return (String)getRowValue(resourceid);
}
public String getResourceid(String key){
return (String) getValue(resourceid,key);
}
@Override
public void removeCache() {
super.removeCache();
}
}

@ -0,0 +1,319 @@
package com.engine.kq.biz;
import com.engine.kq.wfset.util.KQAttFlowCheckUtil;
import weaver.cache.CacheBase;
import weaver.cache.CacheColumn;
import weaver.cache.CacheColumnType;
import weaver.cache.PKColumn;
import weaver.general.Util;
import weaver.systeminfo.SystemEnv;
/**
*
*/
public class KQLeaveRulesComInfo extends CacheBase {
/**
*
*/
protected static String TABLE_NAME = "kq_leaveRules";
/**
* sqlwherewhere
*/
protected static String TABLE_WHERE = " (isDelete is null or isDelete !=1) ";
/**
* sqlorder byorder by
*/
protected static String TABLE_ORDER = " showOrder,id ";
/**
*
*/
@PKColumn(type = CacheColumnType.NUMBER)
protected static String PK_NAME = "id";
/**
*
*/
@CacheColumn(name = "leaveName")
protected static int leaveName;
@CacheColumn(name = "SchevacationON")
protected static int SchevacationON;
@CacheColumn(name = "Schevacation")
protected static int Schevacation;
/**
* 0-1-
*/
@CacheColumn(name = "isEnable")
protected static int isEnable;
/**
* 0-1-
*/
@CacheColumn(name = "scopeType")
protected static int scopeType;
/**
* ID(ID)
*/
@CacheColumn(name = "scopeValue")
protected static int scopeValue;
/**
*
* 1-
* 2-
* 3-
* 4-
*
*/
@CacheColumn(name = "minimumUnit")
protected static int minimumUnit;
/**
*
* XX=1
*/
@CacheColumn(name = "proportion")
protected static int proportion;
/**
* 1=XX
*/
@CacheColumn(name = "hoursToDay")
protected static int hoursToDay;
/**
* 0-1-2-3-
*/
@CacheColumn(name = "filterHolidays")
protected static int filterHolidays;
/**
*
* 1-
* 2-
*/
@CacheColumn(name = "computingMode")
protected static int computingMode;
/**
*
* 0-
* 1-
*/
@CacheColumn(name = "balanceEnable")
protected static int balanceEnable;
/**
*
*/
@CacheColumn(name = "leaveCode")
protected static int leaveCode;
/**
* 1- 2-
*/
@CacheColumn(name = "timeselection")
protected static int timeselection;
/**
* 1 2 3
*/
@CacheColumn(name = "conversion")
protected static int conversion;
/**
* 1 0
*/
@CacheColumn(name = "repeat_time")
protected static int repeatTime;
public String getId(){
return (String)getRowValue(PK_INDEX);
}
public String getLeaveName() {
return (String)getRowValue(leaveName);
}
public String getLeaveName(String key){
return (String) getValue(leaveName,key);
}
public String getSchevacationON() {
return (String)getRowValue(SchevacationON);
}
public String getSchevacationON(String key){
return (String) getValue(SchevacationON,key);
}
public String getSchevacation() {
return (String)getRowValue(Schevacation);
}
public String getSchevacation(String key){
return (String) getValue(Schevacation,key);
}
public String getIsEnable() {
return (String)getRowValue(isEnable);
}
public String getIsEnable(String key){
return (String) getValue(isEnable,key);
}
public String getScopeType() {
return (String)getRowValue(scopeType);
}
public String getScopeType(String key){
return (String) getValue(scopeType,key);
}
public String getScopeValue() {
return (String)getRowValue(scopeValue);
}
public String getScopeValue(String key){
return (String) getValue(scopeValue,key);
}
public String getMinimumUnit() {
return (String)getRowValue(minimumUnit);
}
public String getMinimumUnit(String key){
return (String)getValue(minimumUnit,key);
}
public String getProportion() {
return (String)getRowValue(proportion);
}
public String getProportion(String key){
return (String)getValue(proportion,key);
}
public String getHoursToDay() {
return (String)getRowValue(hoursToDay);
}
public String getHoursToDay(String key){
return (String)getValue(hoursToDay,key);
}
public String getFilterHolidays() {
return (String)getRowValue(filterHolidays);
}
public String getFilterHolidays(String key){
return (String)getValue(filterHolidays,key);
}
public String getComputingMode() {
return (String)getRowValue(computingMode);
}
public String getComputingMode(String key){
return (String)getValue(computingMode,key);
}
public String getBalanceEnable() {
return (String)getRowValue(balanceEnable);
}
public String getBalanceEnable(String key){
return (String)getValue(balanceEnable,key);
}
public String getLeaveCode() {
return (String)getRowValue(leaveCode);
}
public String getLeaveCode(String key){
return (String)getValue(leaveCode,key);
}
public String getTimeSelection() {
String value = (String) getRowValue(timeselection);
if (value == null || value.equals("")) {
value = "1";
}
return value;
}
public String getTimeSelection(String key) {
String value = (String) getValue(timeselection, key);
if (value == null || value.equals("")) {
value = "1";
}
return value;
}
public String getConversion() {
return (String)getRowValue(conversion);
}
public String getConversion(String key){
return (String)getValue(conversion,key);
}
public String getRepeatTime() {
return (String)getRowValue(repeatTime);
}
public String getRepeatTime(String key){
return (String)getValue(repeatTime,key);
}
public String getUnitName(int language){
String unitName = "";//单位名称,天/小时
int minimumUnit = Util.getIntValue(getMinimumUnit(),1);
if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {
unitName = SystemEnv.getHtmlLabelName(389325, language);//(天)
} else {
unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时)
}
return unitName;
}
public String getUnitName(String key,int language){
String unitName = "";//单位名称,天/小时
int minimumUnit = Util.getIntValue(getMinimumUnit(key),1);
if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {
unitName = SystemEnv.getHtmlLabelName(389325, language);//(天)
} else {
unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时)
}
// KQTransMethod method = new KQTransMethod();
// unitName = "("+method.getMinimumUnitName4Browser(""+minimumUnit, ""+language)+")";
return unitName;
}
public String getUnitNameNew(String key,int language){
String unitName = "";//单位名称,天/小时
int minimumUnit = Util.getIntValue(getMinimumUnit(key),1);
if (minimumUnit == 1 || minimumUnit == 2 || minimumUnit == 4) {
unitName = SystemEnv.getHtmlLabelName(389325, language);//(天)
} else {
unitName = SystemEnv.getHtmlLabelName(389326, language);//(小时)
}
return unitName;
}
@Override
public void removeCache() {
super.removeCache();
KQAttFlowCheckUtil kqAttFlowCheckUtil = new KQAttFlowCheckUtil();
kqAttFlowCheckUtil.initLeaveUnit();
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,234 @@
package com.engine.kq.entity;
/**
*
*/
public class KQBalanceOfLeaveEntity {
/**
* ID
*/
int id;
/**
* ID
*/
int leaveRulesId;
/**
* ID
*/
int resourceId;
/**
*
* yyyy
*/
String belongYear;
/**
*
*
*/
double baseAmount = 0.00;
/**
*
*
*/
double usedAmount = 0.00;
/**
*
*
*/
double extraAmount = 0.00;
/**
*
*/
double baseAmount2 = 0.00;
/**
*
*/
double usedAmount2 = 0.00;
/**
*
*/
double extraAmount2 = 0.00;
/**
* 0-1-
*/
int status;
/**
*
*/
String expirationDate;
/**
*
*/
String effectiveDate;
/**
*
*/
int minimumUnit;
public KQBalanceOfLeaveEntity() {
}
public KQBalanceOfLeaveEntity(int id, int leaveRulesId, int resourceId, String belongYear, double baseAmount, double usedAmount, double extraAmount, double baseAmount2, double usedAmount2, double extraAmount2, int status, String expirationDate) {
this.id = id;
this.leaveRulesId = leaveRulesId;
this.resourceId = resourceId;
this.belongYear = belongYear;
this.baseAmount = baseAmount;
this.usedAmount = usedAmount;
this.extraAmount = extraAmount;
this.baseAmount2 = baseAmount2;
this.usedAmount2 = usedAmount2;
this.extraAmount2 = extraAmount2;
this.status = status;
this.expirationDate = expirationDate;
}
public KQBalanceOfLeaveEntity(int id, int leaveRulesId, int resourceId, String belongYear, double baseAmount, double usedAmount, double extraAmount, double baseAmount2, double usedAmount2, double extraAmount2, int status, String expirationDate ,String effectiveDate) {
this.id = id;
this.leaveRulesId = leaveRulesId;
this.resourceId = resourceId;
this.belongYear = belongYear;
this.baseAmount = baseAmount;
this.usedAmount = usedAmount;
this.extraAmount = extraAmount;
this.baseAmount2 = baseAmount2;
this.usedAmount2 = usedAmount2;
this.extraAmount2 = extraAmount2;
this.status = status;
this.expirationDate = expirationDate;
this.effectiveDate = effectiveDate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getLeaveRulesId() {
return leaveRulesId;
}
public void setLeaveRulesId(int leaveRulesId) {
this.leaveRulesId = leaveRulesId;
}
public int getResourceId() {
return resourceId;
}
public void setResourceId(int resourceId) {
this.resourceId = resourceId;
}
public String getBelongYear() {
return belongYear;
}
public void setBelongYear(String belongYear) {
this.belongYear = belongYear;
}
public double getBaseAmount() {
return baseAmount;
}
public void setBaseAmount(double baseAmount) {
this.baseAmount = baseAmount;
}
public double getUsedAmount() {
return usedAmount;
}
public void setUsedAmount(double usedAmount) {
this.usedAmount = usedAmount;
}
public double getExtraAmount() {
return extraAmount;
}
public void setExtraAmount(double extraAmount) {
this.extraAmount = extraAmount;
}
public double getBaseAmount2() {
return baseAmount2;
}
public void setBaseAmount2(double baseAmount2) {
this.baseAmount2 = baseAmount2;
}
public double getUsedAmount2() {
return usedAmount2;
}
public void setUsedAmount2(double usedAmount2) {
this.usedAmount2 = usedAmount2;
}
public double getExtraAmount2() {
return extraAmount2;
}
public void setExtraAmount2(double extraAmount2) {
this.extraAmount2 = extraAmount2;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public String getEffectiveDate() {
return effectiveDate;
}
public void setEffectiveDate(String effectiveDate) {
this.effectiveDate = effectiveDate;
}
public int getMinimumUnit() {
return minimumUnit;
}
public void setMinimumUnit(int minimumUnit) {
this.minimumUnit = minimumUnit;
}
public boolean equals(KQBalanceOfLeaveEntity entity) {
if (this.baseAmount != entity.getBaseAmount()
|| this.extraAmount != entity.getExtraAmount()
|| this.usedAmount != entity.getUsedAmount()
|| this.baseAmount2 != entity.getBaseAmount2()
|| this.extraAmount2 != entity.getExtraAmount2()
|| this.usedAmount2 != entity.getUsedAmount2()) {
return false;
} else {
return true;
}
}
public boolean equalsByBaseAmount(KQBalanceOfLeaveEntity entity) {
if (this.baseAmount != entity.getBaseAmount()
|| this.baseAmount2 != entity.getBaseAmount2()) {
return false;
} else {
return true;
}
}
}

@ -0,0 +1,829 @@
package com.engine.kq.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import com.engine.kq.biz.KQSettingsComInfo;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.ss.util.RegionUtil;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ExcelUtil extends BaseBean {
private boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half"));
/*
*
* */
public Map export(Map<String, Object> workBook, HttpServletRequest request, HttpServletResponse response) throws Exception {
return export(workBook, request, response,false);
}
public Map export(Map<String, Object> workBook, HttpServletRequest request, HttpServletResponse response,boolean isWrap) throws Exception {
Map<String, Object> returnMap = new HashMap<>();
String createFile = "";
try {
SXSSFWorkbook workbook = new SXSSFWorkbook(); // 创建工作簿对象
List<Object> lsSheet = (List<Object>) workBook.get("sheet");
String fileName = Util.null2String(workBook.get("fileName"));
if (fileName.length() == 0||true) fileName = "" + UUID.randomUUID();//解决lunix下中文文件无法生成问题
for (int sheetNum = 0; sheetNum < lsSheet.size(); sheetNum++) {
Map<String, Object> mySheet = (Map<String, Object>) lsSheet.get(sheetNum);
String mySheetName = Util.null2String(mySheet.get("sheetName"));
String sheetTitle = Util.null2String(mySheet.get("sheetTitle"));
List<Object> sheetMemo = (List<Object>) mySheet.get("sheetMemo");
List<Object> titleList = (List<Object>) mySheet.get("titleList");
List<Object> dataList = (List<Object>) mySheet.get("dataList");
List<Map<String, Object>> constraintList = (List<Map<String, Object>>) mySheet.get("constraintList");
createFile = Util.null2String(mySheet.get("createFile"));
int calIndex = Util.getIntValue(Util.null2String(mySheet.get("calIndex")),-1);
Sheet sheet = workbook.createSheet(mySheetName); // 创建工作表
int rowIdx = 0;
// 产生表格标题行
Row rowm = sheet.createRow(rowIdx);
Cell cellTiltle = rowm.createCell(0);
CellStyle titleStyle = this.getTitleStyle(workbook);//获取列头样式对象
CellStyle memoStyle = this.getMemoStyle(workbook);//获取备注样式对象
CellStyle columnTopStyle = this.getColumnTopStyle(workbook);//获取列头样式对象
CellStyle cellStyle = this.getCellStyle(workbook,isWrap); //单元格样式对象
int mergedRegion = titleList.size() - 1;
if (mergedRegion > 15) mergedRegion = 15;
mergedRegion = getColLength(titleList);
CellRangeAddress region = new CellRangeAddress(rowIdx, ++rowIdx, 0, mergedRegion);
RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);
sheet.addMergedRegionUnsafe(region);
cellTiltle.setCellStyle(titleStyle);
cellTiltle.setCellValue(sheetTitle);
for (int i = 0; sheetMemo != null && i < sheetMemo.size(); i++) {
rowm = sheet.createRow(++rowIdx);
Cell cellMemo = rowm.createCell(0);
region = new CellRangeAddress(rowIdx, ++rowIdx, 0, mergedRegion);
RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);
sheet.addMergedRegionUnsafe(region);
cellMemo.setCellStyle(memoStyle);
cellMemo.setCellValue(Util.null2String(sheetMemo.get(i)));
}
// // 定义所需列数
// int columnNum = titleList.size();
// HSSFRow rowRowName = sheet.createRow(++rowIdx); // 在索引2的位置创建行(最顶端的行开始的第二行)
//
// // 将列头设置到sheet的单元格中
// for (int n = 0; n < columnNum; n++) {
// Map title = (Map) titleList.get(n);
//
// HSSFCell cellRowName = rowRowName.createCell(n); //创建列头对应个数的单元格
// cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING); //设置列头单元格的数据类型
// HSSFRichTextString text = new HSSFRichTextString(Util.null2String(title.get("title")));
// cellRowName.setCellValue(text); //设置列头单元格的值
// cellRowName.setCellStyle(columnTopStyle); //设置列头单元格样式
// if (n == 0) {
// sheet.setColumnWidth(n, Util.getIntValue(Util.null2String(title.get("width"))));
// } else {
// sheet.setColumnWidth(n, Util.getIntValue(Util.null2String(title.get("width"))));
// }
// }
rowIdx = this.initDynamicTitle(sheet, titleList, columnTopStyle, rowIdx);
if(isKqReportHalfOpen) {
if(calIndex > -1){
CellStyle style1 = workbook.createCellStyle();
style1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
short amColor = (short) Util.getIntValue("5");
style1.setFillForegroundColor(amColor);
style1.setFillBackgroundColor(IndexedColors.BLUE.index);
style1.setAlignment(HorizontalAlignment.CENTER);
//设置底边框;
style1.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style1.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style1.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style1.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style1.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style1.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style1.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style1.setTopBorderColor(IndexedColors.BLACK.index);
CellStyle style2 = workbook.createCellStyle();
style2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
short pm_color = (short) Util.getIntValue("29");
style2.setFillForegroundColor(pm_color);
style2.setFillBackgroundColor(IndexedColors.RED.index);
style2.setAlignment(HorizontalAlignment.CENTER);
//设置底边框;
style2.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style2.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style2.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style2.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style2.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style2.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style2.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style2.setTopBorderColor(IndexedColors.BLACK.index); //设置单元格样式
//将查询出的数据设置到sheet对应的单元格中
for (int i = 0; dataList != null && i < dataList.size(); ) {
List<Object> obj = (List<Object>) dataList.get(i);//遍历每个对象
int rowNowIndex = i + rowIdx + 1;
Row row = sheet.createRow(rowNowIndex);//创建所需的行数
for (int j = 0; j < obj.size(); j++) {
Cell cell = null; //设置单元格的数据类型
cell = row.createCell(j, CellType.STRING);
if(j < calIndex){
cell.setCellStyle(cellStyle); //设置单元格样式
addMergedRegion(sheet, rowNowIndex, rowNowIndex+1, j, j);
}else{
addMergedRegion(sheet, rowNowIndex, rowNowIndex, j, j);
cell.setCellStyle(style1); //设置单元格样式
}
String value_value = Util.null2String(obj.get(j));
cell.setCellValue(value_value); //设置单元格的值
}
List<Object> obj1 = (List<Object>) dataList.get(i+1);//遍历每个对象
Row row1 = sheet.createRow(rowNowIndex + 1);//创建所需的行数
for (int j = 0; j < obj1.size(); j++) {
Cell cell = null; //设置单元格的数据类型
cell = row1.createCell(j, CellType.STRING);
if(j < calIndex){
cell.setCellStyle(cellStyle); //设置单元格样式
}else{
addMergedRegion(sheet, rowNowIndex+1, rowNowIndex+1, j, j);
cell.setCellStyle(style2);
String value_value = Util.null2String(obj1.get(j));
cell.setCellValue(value_value); //设置单元格的值
}
}
i = i +2;
}
}
} else {
for (int i = 0; dataList != null && i < dataList.size(); i++) {
List<Object> obj = (List<Object>) dataList.get(i);//遍历每个对象
Row row = sheet.createRow(i + rowIdx + 1);//创建所需的行数
for (int j = 0; j < obj.size(); j++) {
Cell cell = null; //设置单元格的数据类型
cell = row.createCell(j, CellType.STRING);
cell.setCellValue(Util.null2String(obj.get(j))); //设置单元格的值
cell.setCellStyle(cellStyle); //设置单元格样式
}
}
}
// int columnNum = this.getColumnLength(titleList);
// //让列宽随着导出的列长自动适应
// for (int colNum = 0; colNum < columnNum; colNum++) {
// int columnWidth = sheet.getColumnWidth(colNum) / 256;
// for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
// HSSFRow currentRow;
// //当前行未被使用过
// if (sheet.getRow(rowNum) == null) {
// currentRow = sheet.createRow(rowNum);
// } else {
// currentRow = sheet.getRow(rowNum);
// }
// if (currentRow.getCell(colNum) != null) {
// //取得当前的单元格
// HSSFCell currentCell = currentRow.getCell(colNum);
// //如果当前单元格类型为字符串
// if (currentCell.getCellTypeEnum() == CellType.STRING) {
// int length = currentCell.getStringCellValue().getBytes().length;
// if (columnWidth < length) {
// //将单元格里面值大小作为列宽度
// columnWidth = length;
// }
// }
// }
// }
// //再根据不同列单独做下处理
// if (colNum == 0) {
// sheet.setColumnWidth(colNum, (columnWidth - 2) * 256);
// } else {
// sheet.setColumnWidth(colNum, (columnWidth + 4) * 256);
// }
// }
for (int i = 0; constraintList != null && i < constraintList.size(); i++) {
Map<String, Object> constraint = constraintList.get(i);
int firstRow = Util.getIntValue(Util.null2String(constraint.get("firstRow")), 0);
int endRow = Util.getIntValue(Util.null2String(constraint.get("endRow")), 0);
int firstCol = Util.getIntValue(Util.null2String(constraint.get("firstCol")), 0);
int endCol = Util.getIntValue(Util.null2String(constraint.get("endCol")), 0);
//设置下拉框数据
String[] datas = (String[]) constraint.get("constraintDatas");
String hiddenSheetName = "constraintDataSheet"+i;
Sheet hiddenSheet = workbook.createSheet(hiddenSheetName);
workbook.setSheetHidden(workbook.getSheetIndex(hiddenSheet), true);
for (int j = 0; j< datas.length; j++) {
hiddenSheet.createRow(j).createCell(0).setCellValue(datas[j]);
}
DataValidationHelper helper = sheet.getDataValidationHelper();
String formulaId = hiddenSheetName + "!$A$1:$A$" + datas.length;
DataValidationConstraint dataValidationConstraint = helper.createFormulaListConstraint(formulaId);
CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
DataValidation dataValidation = helper.createValidation(dataValidationConstraint, cellRangeAddressList);
//处理Excel兼容性问题
if (dataValidation instanceof DataValidation) {
dataValidation.setSuppressDropDownArrow(true);
dataValidation.setShowErrorBox(true);
} else {
dataValidation.setSuppressDropDownArrow(false);
}
sheet.addValidationData(dataValidation);
}
// for (int i = 0; constraintList != null && i < constraintList.size(); i++) {
// Map<String, Object> constraint = constraintList.get(i);
// int firstRow = Util.getIntValue(Util.null2String(constraint.get("firstRow")), 0);
// int endRow = Util.getIntValue(Util.null2String(constraint.get("endRow")), 0);
// int firstCol = Util.getIntValue(Util.null2String(constraint.get("firstCol")), 0);
// int endCol = Util.getIntValue(Util.null2String(constraint.get("endCol")), 0);
//
// //设置下拉框数据
// String[] datas = (String[]) constraint.get("constraintDatas");
// DataValidationHelper helper = sheet.getDataValidationHelper();
// DataValidationConstraint dataValidationConstraint = helper.createExplicitListConstraint(datas);
// CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
// DataValidation dataValidation = helper.createValidation(dataValidationConstraint, cellRangeAddressList);
// //处理Excel兼容性问题
// if (dataValidation instanceof DataValidation) {
// dataValidation.setSuppressDropDownArrow(true);
// dataValidation.setShowErrorBox(true);
// } else {
// dataValidation.setSuppressDropDownArrow(false);
// }
// sheet.addValidationData(dataValidation);
// }
}
if (workbook != null) {
if (createFile.equals("1")) {
String filePath = GCONST.getRootPath() + "/hrm/kq/tmpFile/";
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
}
fileName = fileName +"("+DateUtil.getNowDateTimeStr()+")";
String url = filePath + fileName + ".xlsx";
String realUrl = "/hrm/kq/tmpFile/" + fileName + ".xlsx";
FileOutputStream fOut = new FileOutputStream(url);
workbook.write(fOut);
fOut.flush();
fOut.close();
returnMap.put("url", realUrl);
} else {
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setCharacterEncoding("utf-8");
String header = request.getHeader("User-Agent").toUpperCase();
if (header.contains("MSIE") || header.contains("TRIDENT") || header.contains("EDGE")) {
fileName = URLEncoder.encode(fileName, "utf-8");
fileName = fileName.replace("+", "%20"); //IE下载文件名空格变+号问题
} else {
fileName = new String(fileName.getBytes("utf-8"), "ISO_8859_1");
}
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
response.setContentType("application/msexcel");
response.setContentType("application/x-msdownload");
OutputStream responseOutput = response.getOutputStream();
workbook.write(responseOutput);
responseOutput.flush();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return returnMap;
}
/*
*
*/
private CellStyle getMemoStyle(SXSSFWorkbook workbook) {
// 设置字体
Font font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short) 10);
//字体加粗
font.setBold(true);
//设置字体名字
font.setFontName("宋体");
//设置样式;
CellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style.setTopBorderColor(IndexedColors.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(false);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HorizontalAlignment.LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/*
*
*/
private CellStyle getTitleStyle(SXSSFWorkbook workbook) {
// 设置字体
Font font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short) 14);
//字体加粗
font.setBold(true);
//设置字体名字
font.setFontName("宋体");
//设置样式;
CellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style.setTopBorderColor(IndexedColors.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(false);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HorizontalAlignment.CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/*
*
*/
private CellStyle getColumnTopStyle(SXSSFWorkbook workbook) {
// 设置字体
Font font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short) 11);
//字体加粗
font.setBold(true);
//设置字体名字
font.setFontName("宋体");
//设置样式;
CellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style.setTopBorderColor(IndexedColors.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HorizontalAlignment.CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/*
*
*/
private CellStyle getCellStyle(SXSSFWorkbook workbook,boolean isWrap) {
// 设置字体
Font font = workbook.createFont();
//设置字体大小
//font.setFontHeightInPoints((short)10);
//字体加粗
//font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//设置字体名字
font.setFontName("宋体");
//设置样式;
CellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style.setTopBorderColor(IndexedColors.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
// style.setWrapText(false);
if(isWrap){
style.setWrapText(true);
}else{
style.setWrapText(false);
}
//设置水平对齐的样式为居中对齐;
style.setAlignment(HorizontalAlignment.LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
private CellStyle getCellStyle(SXSSFWorkbook workbook) {
// 设置字体
Font font = workbook.createFont();
//设置字体大小
//font.setFontHeightInPoints((short)10);
//字体加粗
//font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//设置字体名字
font.setFontName("宋体");
//设置样式;
CellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(BorderStyle.THIN);
//设置底边框颜色;
style.setBottomBorderColor(IndexedColors.BLACK.index);
//设置左边框;
style.setBorderLeft(BorderStyle.THIN);
//设置左边框颜色;
style.setLeftBorderColor(IndexedColors.BLACK.index);
//设置右边框;
style.setBorderRight(BorderStyle.THIN);
//设置右边框颜色;
style.setRightBorderColor(IndexedColors.BLACK.index);
//设置顶边框;
style.setBorderTop(BorderStyle.THIN);
//设置顶边框颜色;
style.setTopBorderColor(IndexedColors.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(false);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HorizontalAlignment.LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
public static void main(String[] args) {
String groupid = "1";
String filename = "c://33e2a90d-3347-490c-afff-21de0ef3e3af.xlsx";
int startRow = 3;
RecordSet rs = new RecordSet();
String sql = "";
try {
//必要的权限判断
List<List> lsParams = null;
List params = null;
Workbook workbook = WorkbookFactory.create(new FileInputStream(filename));
for (int idx = 0; idx < workbook.getNumberOfSheets(); idx++) {
Sheet sheet = workbook.getSheetAt(idx);
Row row = null;
Cell cell = null;
lsParams = new ArrayList();
for (int i = startRow; startRow <= sheet.getLastRowNum() && i <= sheet.getLastRowNum(); i++) {
row = sheet.getRow(i);
if (row == null) {
continue;
}
params = new ArrayList();
for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) {
cell = row.getCell((short) cellIndex);
if (cell == null) continue;
params.add(getCellValue(cell).trim());
}
params.add(groupid);
if (Util.null2String(params.get(0)).length() > 0) {
lsParams.add(params);
}
}
if (idx == 0) {
sql = "insert into kq_loaction (loactionname,longitude,latitude,address,groupid) values (?,?,?,?,?) ";
} else {
sql = "insert into kq_wifi (wifiname,mac,groupid) values (?,?,?) ";
}
rs.executeBatchSql(sql, lsParams);
}
} catch (Exception e) {
new BaseBean().writeLog(e);
}
}
public int initDynamicTitle(Sheet sheet, List<Object> columns, CellStyle columnTopStyle, int rowIdx) {
int cur_rowIndx = rowIdx+1;
//title 总行数
int title_rows = cur_rowIndx+getRowNums(columns)-1;
createHeaderRow(sheet, cur_rowIndx, 0,columns,columnTopStyle,title_rows);
return title_rows;
}
/**
*
*/
private int createHeaderRow(Sheet sheet, int index, int cellIndex,
List<Object> columnName, CellStyle columnTopStyle, int title_rows) {
Row row = sheet.getRow(index) == null ? sheet.createRow(index) : sheet.getRow(index);
int rows = getRowNums(columnName);
for (int i = 0, exportFieldTitleSize = columnName.size(); i < exportFieldTitleSize; i++) {
Map<String,Object> column = (Map<String, Object>) columnName.get(i);
String title = Util.null2String(column.get("title"));
createStringCell(row, cellIndex, title, columnTopStyle);
if (column.get("children") != null) {
List<Object> childchildColumns = (List<Object>) column.get("children");
// 保持原来的
int tempCellIndex = cellIndex;
cellIndex = createHeaderRow(sheet, rows == 1 ? index : index + 1, cellIndex, childchildColumns,columnTopStyle,
title_rows);
if (childchildColumns.size() > 1) {
addMergedRegion(sheet, index, index, tempCellIndex, cellIndex - 1);
}
cellIndex--;
}else{
addMergedRegion(sheet, index, title_rows, cellIndex, cellIndex);
}
cellIndex++;
}
return cellIndex;
}
/**
*
* @param sheet
* @param firstRow
* @param lastRow
* @param firstCol
* @param lastCol
*/
public void addMergedRegion(Sheet sheet, int firstRow, int lastRow, int firstCol, int lastCol) {
try {
if(firstRow == lastRow && firstCol == lastCol){
return ;
}
CellRangeAddress region = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);
sheet.addMergedRegionUnsafe(region);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Cell
*/
public void createStringCell(Row row, int cellIndex, String title, CellStyle columnTopStyle) {
Cell cellRowName = row.createCell(cellIndex); //创建列头对应个数的单元格
cellRowName.setCellType(CellType.STRING); //设置列头单元格的数据类型
cellRowName.setCellValue(title); //设置列头单元格的值
cellRowName.setCellStyle(columnTopStyle); //设置列头单元格样式
}
public int initTitle(Sheet sheet, List<Object> columns, CellStyle columnTopStyle, int rowIdx) {
List<Object> lsMergedRegion = new ArrayList<>();
Map<String, Object> mergedRegion = null;
int firstTitleRow = rowIdx + 1;
int lastTitleRow = rowIdx + 2;
Row rowRowName = sheet.createRow(++rowIdx); // 在索引2的位置创建行(最顶端的行开始的第二行)
Row childRowRowName = null;
// 定义所需列数
Map<String, Object> column = null;
List<Object> childColumn = null;
int colIdx = 0;
for (int i = 0; i < columns.size(); i++) {
column = (Map<String, Object>) columns.get(i);
childColumn = (List<Object>) column.get("children");
Cell cellRowName = rowRowName.createCell(colIdx++); //创建列头对应个数的单元格
cellRowName.setCellType(CellType.STRING); //设置列头单元格的数据类型
cellRowName.setCellValue(Util.null2String(column.get("title"))); //设置列头单元格的值
cellRowName.setCellStyle(columnTopStyle); //设置列头单元格样式
if (Util.getIntValue(Util.null2String(column.get("rowSpan"))) == 2) {
if (childRowRowName == null) {
childRowRowName = sheet.createRow(++rowIdx);
}
mergedRegion = new HashMap<String, Object>();
mergedRegion.put("startRow", firstTitleRow);
mergedRegion.put("overRow", lastTitleRow);
mergedRegion.put("startCol", colIdx - 1);
mergedRegion.put("overCol", colIdx - 1);
lsMergedRegion.add(mergedRegion);
}
if (childColumn != null) {
colIdx--;
mergedRegion = new HashMap<String, Object>();
mergedRegion.put("startRow", firstTitleRow);
mergedRegion.put("overRow", firstTitleRow);
mergedRegion.put("startCol", colIdx);
for (int j = 0; j < childColumn.size(); j++) {
column = (Map<String, Object>) childColumn.get(j);
cellRowName = childRowRowName.createCell(colIdx++); //创建列头对应个数的单元格
cellRowName.setCellType(CellType.STRING); //设置列头单元格的数据类型
cellRowName.setCellValue(Util.null2String(column.get("title"))); //设置列头单元格的值
cellRowName.setCellStyle(columnTopStyle);
}
mergedRegion.put("overCol", colIdx - 1);
if (childColumn.size() > 1) {
lsMergedRegion.add(mergedRegion);
}
}
}
for (int i = 0; i < lsMergedRegion.size(); i++) {
mergedRegion = (Map<String, Object>) lsMergedRegion.get(i);
Integer startrow = Util.getIntValue(Util.null2String(mergedRegion.get("startRow")));
Integer overrow = Util.getIntValue(Util.null2String(mergedRegion.get("overRow")));
Integer startcol = Util.getIntValue(Util.null2String(mergedRegion.get("startCol")));
Integer overcol = Util.getIntValue(Util.null2String(mergedRegion.get("overCol")));
CellRangeAddress region = new CellRangeAddress(startrow, overrow, startcol, overcol);
RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);
RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);
sheet.addMergedRegionUnsafe(region);
}
return rowIdx;
}
/**
*
* @param columns
* @return
*/
private int getColLength(List<Object> columns) {
int length = -1;// 从0开始计算单元格的
for(int i =0 ; i < columns.size() ; i++){
Map<String,Object> column = (Map<String, Object>) columns.get(i);
if (column.get("children") != null) {
List<Object> childchildColumns = (List<Object>) column.get("children");
length += getColLength(childchildColumns) + 1;
} else {
length++;
}
}
return length;
}
/**
*
*/
public int getRowNums(List<Object> columns) {
int cnt = 1;
for (int i = 0; i < columns.size(); i++) {
Map<String,Object> column = (Map<String, Object>) columns.get(i);
if (column.get("children") != null) {
List<Object> childchildColumns = (List<Object>) column.get("children");
int tmpcnt = 1+getRowNums(childchildColumns);
if(tmpcnt > cnt){
cnt = tmpcnt;
}
}
}
if(cnt > 1){
return cnt;
}else{
return 1;
}
}
public int getColumnLength(List<Object> columns) {
int columnLength = 0;
Map<String, Object> column = null;
for (int i = 0; i < columns.size(); i++) {
column = (Map<String, Object>) columns.get(i);
if (column.get("colSpan") != null) {
columnLength += Util.getIntValue(Util.null2String(column.get("colSpan")));
} else {
columnLength++;
}
}
return columnLength;
}
/**
* /**
* excel
*
* @param cell
* @return
*/
public static String getCellValue(Cell cell) {
String cellValue = "";
if (cell == null)
return "";
switch (cell.getCellType()) {
case BOOLEAN: // 得到Boolean对象的方法
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case NUMERIC:
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {// 先看是否是日期格式
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
cellValue = String.valueOf(sft.format(cell.getDateCellValue())); // 读取日期格式
} else {
cellValue = String.valueOf(new Double(cell.getNumericCellValue())); // 读取数字
if (cellValue.endsWith(".0"))
cellValue = cellValue.substring(0, cellValue.indexOf("."));
}
break;
case FORMULA: // 读取公式
cellValue = cell.getCellFormula();
break;
case STRING: // 读取String
cellValue = cell.getStringCellValue();
break;
}
return cellValue;
}
}
Loading…
Cancel
Save