Commit 8365a39f authored by 廖旭伟's avatar 廖旭伟

目录增加生成证照目录Excel导入文件模板接口

parent 170ed31e
...@@ -691,6 +691,7 @@ data|object|数据对象 ...@@ -691,6 +691,7 @@ data|object|数据对象
  updateUserId|Long|更新用户   updateUserId|Long|更新用户
  updateTime|Date|更新时间   updateTime|Date|更新时间
  deviceId|Long|打印设备Id   deviceId|Long|打印设备Id
  excelFile|String|批量导入模板文件地址
dict|object|字典对象 dict|object|字典对象
**响应消息样例:** **响应消息样例:**
...@@ -751,6 +752,7 @@ data|object|数据对象 ...@@ -751,6 +752,7 @@ data|object|数据对象
 updateUserId|Long|更新用户  updateUserId|Long|更新用户
 updateTime|Date|更新时间  updateTime|Date|更新时间
 deviceId|Long|打印设备Id  deviceId|Long|打印设备Id
 excelFile|String|批量导入模板文件地址
dict|object|字典对象 dict|object|字典对象
**响应消息样例:** **响应消息样例:**
...@@ -866,6 +868,7 @@ data|object|数据对象 ...@@ -866,6 +868,7 @@ data|object|数据对象
  updateUserId|Long|更新用户   updateUserId|Long|更新用户
  updateTime|Date|更新时间   updateTime|Date|更新时间
  deviceId|Long|打印设备Id   deviceId|Long|打印设备Id
  excelFile|String|批量导入模板文件地址
**响应消息样例:** **响应消息样例:**
``` ```
...@@ -913,6 +916,45 @@ msg|String|消息|- ...@@ -913,6 +916,45 @@ msg|String|消息|-
} }
``` ```
### 生成证照目录Excel导入文件
**请求URL:** certificate/catalog/generate/excel
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 生成证照目录Excel导入文件
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
id|Long|是|ID
**请求样例:**
```
http://localhost/certificate/catalog/generate/excel?id=549
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:-------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
**响应消息样例:**
```
{
"msg":"生成证照目录Excel导入文件成功",
"code":1,
"data":{}
}
}
```
## 证照柜设备 ## 证照柜设备
### 查询证照柜设备列表 ### 查询证照柜设备列表
......
package com.mortals.xhx.common.utils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddressList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
public class ExcelUtil {
/**
* @Title: createExcelTemplate
* @Description: 生成Excel导入模板
* @param @param filePath Excel文件路径
* @param @param handers Excel列标题(数组)
* @param @param downData 下拉框数据(数组)
* @param @param downRows 下拉列的序号(数组,序号从0开始)
* @return void
* @throws
*/
public static void createExcelTemplate(String filePath, String[] title, List<String[]> downData, String[] downRows){
HSSFWorkbook wb = new HSSFWorkbook();//创建工作薄
//表头样式
HSSFCellStyle style = wb.createCellStyle();
// 创建一个居中格式
// style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//字体样式
HSSFFont fontStyle = wb.createFont();
fontStyle.setFontName("微软雅黑");
fontStyle.setFontHeightInPoints((short)12);
// fontStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style.setFont(fontStyle);
// 新建sheet
HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2");
HSSFSheet sheet3 = wb.createSheet("Sheet3");
// 生成sheet1内容
// 第一个sheet的第一行为标题
HSSFRow rowFirst = sheet1.createRow(0);
// 写标题
for(int i=0;i<title.length;i++){
// 获取第一行的每个单元格
HSSFCell cell = rowFirst.createCell(i);
// 设置每列的列宽
sheet1.setColumnWidth(i, 4000);
//加样式
cell.setCellStyle(style);
// 往单元格里写数据
cell.setCellValue(title[i]);
}
// 设置下拉框数据
String[] arr = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int index = 0;
HSSFRow row = null;
for(int r=0;r<downRows.length;r++){
// 获取下拉对象
String[] dlData = downData.get(r);
int rownum = Integer.parseInt(downRows[r]);
// 255以内的下拉
if(dlData.length<5){
// 255以内的下拉,参数分别是:作用的sheet、下拉内容数组、起始行、终止行、起始列、终止列
sheet1.addValidationData(setDataValidation(sheet1, dlData, 1, 500, rownum ,rownum)); //超过255个报错
} else {
// 255以上的下拉,即下拉列表元素很多的情况
// 1、设置有效性
// Sheet2第A1到A5000作为下拉列表来源数据
// String strFormula = "Sheet2!$A$1:$A$5000" ;
// Sheet2第A1到A5000作为下拉列表来源数据
String strFormula = "Sheet2!$"+arr[index]+"$1:$"+arr[index]+"$5000";
// 设置每列的列宽
sheet2.setColumnWidth(r, 4000);
// 设置数据有效性加载在哪个单元格上,参数分别是:从sheet2获取A1到A5000作为一个下拉的数据、起始行、终止行、起始列、终止列
//下拉列表元素很多的情况
sheet1.addValidationData(SetDataValidation(strFormula, 1, 50000, rownum, rownum));
//2、生成sheet2内容
for(int j=0;j<dlData.length;j++){
if(index==0){ //第1个下拉选项,直接创建行、列
// 创建数据行
row = sheet2.createRow(j);
// 设置每列的列宽
sheet2.setColumnWidth(j, 4000);
// 设置对应单元格的值
row.createCell(0).setCellValue(dlData[j]);
} else { //非第1个下拉选项
int rowCount = sheet2.getLastRowNum();
//System.out.println("========== LastRowNum =========" + rowCount);
// 前面创建过的行,直接获取行,创建列
if(j<=rowCount){
// 获取行,创建列
// 设置对应单元格的值
sheet2.getRow(j).createCell(index).setCellValue(dlData[j]);
} else { //未创建过的行,直接创建行、创建列
// 设置每列的列宽
sheet2.setColumnWidth(j, 4000);
// 创建行、创建列
// 设置对应单元格的值
sheet2.createRow(j).createCell(index).setCellValue(dlData[j]);
}
}
}
index++;
}
}
try {
File f = new File(filePath); //写文件
//不存在则新增
if(!f.getParentFile().exists()){
f.getParentFile().mkdirs();
}
if(!f.exists()){
f.createNewFile();
}
FileOutputStream out = new FileOutputStream(f);
out.flush();
wb.write(out);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
*
* @Title: SetDataValidation
* @Description: 下拉列表元素很多的情况 (255以上的下拉)
* @param @param strFormula
* @param @param firstRow 起始行
* @param @param endRow 终止行
* @param @param firstCol 起始列
* @param @param endCol 终止列
* @param @return
* @return HSSFDataValidation
* @throws
*/
private static HSSFDataValidation SetDataValidation(String strFormula, int firstRow, int endRow, int firstCol, int endCol) {
// 设置数据有效性加载在哪个单元格上。四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
DVConstraint constraint = DVConstraint.createFormulaListConstraint(strFormula);
HSSFDataValidation dataValidation = new HSSFDataValidation(regions,constraint);
dataValidation.createErrorBox("Error", "Error");
dataValidation.createPromptBox("", null);
return dataValidation;
}
/**
*
* @Title: setDataValidation
* @Description: 下拉列表元素不多的情况(255以内的下拉)
* @param @param sheet
* @param @param textList
* @param @param firstRow
* @param @param endRow
* @param @param firstCol
* @param @param endCol
* @param @return
* @return DataValidation
* @throws
*/
private static DataValidation setDataValidation(Sheet sheet, String[] textList, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
//加载下拉列表内容
DataValidationConstraint constraint = helper.createExplicitListConstraint(textList);
//DVConstraint constraint = new DVConstraint();
constraint.setExplicitListValues(textList);
//设置数据有效性加载在哪个单元格上。四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow,firstCol, endCol);
//数据有效性对象
DataValidation data_validation = helper.createValidation(constraint, regions);
//DataValidation data_validation = new DataValidation(regions, constraint);
return data_validation;
}
/**
* @Title: delFile
* @Description: 删除文件
* @param @param filePath 文件路径
* @return void
* @throws
*/
public static void delFile(String filePath) {
java.io.File delFile = new java.io.File(filePath);
delFile.delete();
}
}
package com.mortals.xhx.module.certificate.service; package com.mortals.xhx.module.certificate.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.certificate.model.CertificateCatalogEntity; import com.mortals.xhx.module.certificate.model.CertificateCatalogEntity;
/** /**
...@@ -11,4 +12,9 @@ import com.mortals.xhx.module.certificate.model.CertificateCatalogEntity; ...@@ -11,4 +12,9 @@ import com.mortals.xhx.module.certificate.model.CertificateCatalogEntity;
*/ */
public interface CertificateCatalogService extends ICRUDService<CertificateCatalogEntity,Long>{ public interface CertificateCatalogService extends ICRUDService<CertificateCatalogEntity,Long>{
/**
* 生成excel批量导入模板
* @param id
*/
void generateExcel(Long id, Context context);
} }
\ No newline at end of file
...@@ -14,6 +14,7 @@ import com.mortals.xhx.common.code.ComponentEnum; ...@@ -14,6 +14,7 @@ import com.mortals.xhx.common.code.ComponentEnum;
import com.mortals.xhx.common.code.StatusEnum; import com.mortals.xhx.common.code.StatusEnum;
import com.mortals.xhx.common.formdesign.*; import com.mortals.xhx.common.formdesign.*;
import com.mortals.xhx.common.pdu.gen.component.ComponentCons; import com.mortals.xhx.common.pdu.gen.component.ComponentCons;
import com.mortals.xhx.common.utils.ExcelUtil;
import com.mortals.xhx.common.utils.StringUtils; import com.mortals.xhx.common.utils.StringUtils;
import com.mortals.xhx.module.certificate.model.CertificateClassifyEntity; import com.mortals.xhx.module.certificate.model.CertificateClassifyEntity;
import com.mortals.xhx.module.certificate.service.CertificateClassifyService; import com.mortals.xhx.module.certificate.service.CertificateClassifyService;
...@@ -69,7 +70,8 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi ...@@ -69,7 +70,8 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi
} }
entity.setStatus(StatusEnum.ENABLE.getValue()); entity.setStatus(StatusEnum.ENABLE.getValue());
if(StringUtils.isNotEmpty(entity.getTemplateUrl())){ if(StringUtils.isNotEmpty(entity.getTemplateUrl())){
entity.setFormContent(parseDocxToJson(entity.getTemplateUrl())); //entity.setFormContent(parseDocxToJson(entity.getTemplateUrl()));
parseDocxToJson(entity,false);
} }
} }
...@@ -106,9 +108,9 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi ...@@ -106,9 +108,9 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi
} }
} }
private String parseDocxToJson(String templatePath) { private void parseDocxToJson(CertificateCatalogEntity entity,boolean onlyExcel) {
String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/"; String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/";
String filepath = rootPath + templatePath; String filepath = rootPath + entity.getTemplateUrl();
ConfigureBuilder builder = Configure.builder(); ConfigureBuilder builder = Configure.builder();
builder.setValidErrorHandler(new Configure.DiscardHandler()); builder.setValidErrorHandler(new Configure.DiscardHandler());
...@@ -122,6 +124,16 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi ...@@ -122,6 +124,16 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi
root.setConfig(config); root.setConfig(config);
List<ListItem> collect = new ArrayList<>(); List<ListItem> collect = new ArrayList<>();
HashSet<String> hs = new HashSet<>(); //去除重复标签 HashSet<String> hs = new HashSet<>(); //去除重复标签
List<String> excelList = new ArrayList<>(); //Excel模板
excelList.add("证照目录ID");
excelList.add("证照编号");
excelList.add("证照名称");
excelList.add("颁发时间");
excelList.add("取件人姓名");
excelList.add("取件人证件号码");
excelList.add("持有者名称");
excelList.add("持有者证件号码");
excelList.add("企业名称");
for (MetaTemplate item : template.getElementTemplates()) { for (MetaTemplate item : template.getElementTemplates()) {
if(hs.contains(item.variable())){ if(hs.contains(item.variable())){
continue; continue;
...@@ -130,6 +142,7 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi ...@@ -130,6 +142,7 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi
} }
//识别简单输入 //识别简单输入
String val = StrUtil.strip(item.variable(), "{{", "}}"); String val = StrUtil.strip(item.variable(), "{{", "}}");
excelList.add(val);
List<String> keys = StrSplitter.split(val, "_", true, true); List<String> keys = StrSplitter.split(val, "_", true, true);
//切分分隔符后动态 创建组件 i_1_姓名(第一个代表类型,第二个如果是多个累加,第三个显示label) //切分分隔符后动态 创建组件 i_1_姓名(第一个代表类型,第二个如果是多个累加,第三个显示label)
if (keys.size() > 2) { if (keys.size() > 2) {
...@@ -180,6 +193,33 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi ...@@ -180,6 +193,33 @@ public class CertificateCatalogServiceImpl extends AbstractCRUDServiceImpl<Certi
} }
} }
root.setList(collect); root.setList(collect);
return JSON.toJSONString(root); String fileName = "file/uploadfile/excel/"+entity.getCatalogName()+"_批量导入模板.xls";
String excelFilePath = rootPath + fileName;
List<String[]> downData = new ArrayList();
String [] downRows = {};
ExcelUtil.createExcelTemplate(excelFilePath, excelList.toArray(new String[excelList.size()]), downData, downRows);
entity.setExcelFile(fileName);
if(!onlyExcel) {
entity.setFormContent(JSON.toJSONString(root));
}
}
public static void main(String[] args){
String excelFilePath = "D:/mortals/app/data/cpm/" + "excel/test.xls";
List<String> excelList = new ArrayList<>();
excelList.add("i_1_姓名");
excelList.add("i_2_性别");
excelList.add("i_3_年龄");
excelList.add("i_4_证件编号");
excelList.add("i_5_证件名称");
List<String[]> downData = new ArrayList();
String [] downRows = {};
ExcelUtil.createExcelTemplate(excelFilePath, excelList.toArray(new String[excelList.size()]), downData, downRows);
}
@Override
public void generateExcel(Long id, Context context) {
CertificateCatalogEntity entity = dao.get(id);
parseDocxToJson(entity,true);
} }
} }
\ No newline at end of file
...@@ -54,7 +54,7 @@ public class CertificateClassifyServiceImpl extends AbstractCRUDServiceImpl<Cert ...@@ -54,7 +54,7 @@ public class CertificateClassifyServiceImpl extends AbstractCRUDServiceImpl<Cert
@Override @Override
public void setShowFront(List<Long> ids, int showFront) throws AppException { public void setShowFront(List<Long> ids, int showFront) throws AppException {
if(CollectionUtils.isEmpty(ids)){ if(CollectionUtils.isEmpty(ids)){
throw new AppException("分类主键List不能为空"); ids.add(-1L);
} }
Map<String,Object> condition = new HashMap<>(); Map<String,Object> condition = new HashMap<>();
condition.put("idList",ids); condition.put("idList",ids);
......
package com.mortals.xhx.module.certificate.web; package com.mortals.xhx.module.certificate.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.IBaseEnum; import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
...@@ -52,5 +53,30 @@ public class CertificateCatalogController extends BaseCRUDJsonBodyMappingControl ...@@ -52,5 +53,30 @@ public class CertificateCatalogController extends BaseCRUDJsonBodyMappingControl
super.init(model, context); super.init(model, context);
} }
@RequestMapping(value = {"generate/excel"},method = {RequestMethod.POST, RequestMethod.GET})
@UnAuth
public String generateExcel(Long id) {
Map<String, Object> model = new HashMap();
if (id == null) {
return this.createFailJsonResp("请选择待处理" + this.getModuleDesc() + "信息");
} else {
JSONObject ret = new JSONObject();
String busiDesc = "生成Excel导入模板";
Context context = this.getContext();
try {
this.service.generateExcel(id, context);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var8) {
this.doException(this.request, busiDesc, model, var8);
Object msg = model.get("message_info");
return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
}
this.init(model, context);
ret.put("data", model);
ret.put("code", 1);
ret.put("msg", model.remove("message_info"));
return ret.toJSONString();
}
}
} }
\ No newline at end of file
...@@ -115,6 +115,7 @@ public class ApplyLogController extends BaseCRUDJsonBodyMappingController<ApplyL ...@@ -115,6 +115,7 @@ public class ApplyLogController extends BaseCRUDJsonBodyMappingController<ApplyL
ret.setCode(VALUE_RESULT_SUCCESS); ret.setCode(VALUE_RESULT_SUCCESS);
ret.setMsg("查询档案成功"); ret.setMsg("查询档案成功");
ret.setData(list); ret.setData(list);
this.recordSysLog(this.request, " 查询档案成功【成功】");
} catch (Exception e) { } catch (Exception e) {
log.error("查询档案异常", e); log.error("查询档案异常", e);
ret.setCode(VALUE_RESULT_FAILURE); ret.setCode(VALUE_RESULT_FAILURE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment