From 43f38b24dfefb053445825725a82a46e2078e285 Mon Sep 17 00:00:00 2001 From: YaoJianze <1328185723@qq.com> Date: Tue, 23 Apr 2024 18:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=88=B6=E5=BC=8F=E8=A1=A8=E6=A0=BC=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97=20=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=EF=BC=9A=E8=83=BD=E5=A4=9F=E6=8C=89=E7=85=A7=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=B0=86=E8=A1=A8=E6=A0=BC=E5=AF=BC=E5=87=BA=E4=B8=BA?= =?UTF-8?q?Excel=E3=80=81Word=E6=88=96PDF=E6=96=87=E4=BB=B6=20=E5=9C=A8?= =?UTF-8?q?=E5=90=84=E4=B8=AA=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bianmu/controller/MetadataController.java | 44 ++- .../static/js/business/metadata/metadata.js | 22 +- .../view/business/metadata/metadata.html | 1 + shandan-browser/pom.xml | 12 + .../keyware/shandan/BrowserApplication.java | 1 + .../controller/CustomFormController.java | 91 ++++++ .../browser/controller/SearchController.java | 20 +- .../shandan/browser/entity/CustomForm.java | 43 +++ .../browser/mapper/CustomFormMapper.java | 15 + .../browser/service/CustomFormService.java | 14 + .../service/impl/CustomFormServiceImpl.java | 20 ++ .../main/resources/static/css/customForm.css | 48 +++ .../main/resources/static/js/customForm.js | 113 +++++++ .../main/resources/static/js/meta_search.js | 31 +- .../src/main/resources/static/js/report.js | 1 - .../src/main/resources/view/CustomFrom.html | 127 ++++++++ .../src/main/resources/view/meta_search.html | 10 + .../src/main/resources/view/report.html | 10 + .../main/resources/static/js/common/common.js | 2 + shandan-system/pom.xml | 6 + .../controller/MetadataCommonController.java | 2 +- .../bianmu/entity/DirectoryResource.java | 9 + .../bianmu/export/DirectoryExport.java | 81 ++++- .../shandan/bianmu/export/ExportProgress.java | 1 + .../bianmu/export/FileSearchExport.java | 5 + .../bianmu/export/MetaTableExport.java | 294 ++++++++++++++++-- .../system/controller/SysFileController.java | 1 - .../system/utils/Word2PdfAsposeUtil.java | 82 +++++ .../src/main/resources/Aspose.license.lic | 20 ++ 29 files changed, 1085 insertions(+), 41 deletions(-) create mode 100644 shandan-browser/src/main/java/com/keyware/shandan/browser/controller/CustomFormController.java create mode 100644 shandan-browser/src/main/java/com/keyware/shandan/browser/entity/CustomForm.java create mode 100644 shandan-browser/src/main/java/com/keyware/shandan/browser/mapper/CustomFormMapper.java create mode 100644 shandan-browser/src/main/java/com/keyware/shandan/browser/service/CustomFormService.java create mode 100644 shandan-browser/src/main/java/com/keyware/shandan/browser/service/impl/CustomFormServiceImpl.java create mode 100644 shandan-browser/src/main/resources/static/css/customForm.css create mode 100644 shandan-browser/src/main/resources/static/js/customForm.js create mode 100644 shandan-browser/src/main/resources/view/CustomFrom.html create mode 100644 shandan-system/src/main/java/com/keyware/shandan/system/utils/Word2PdfAsposeUtil.java create mode 100644 shandan-system/src/main/resources/Aspose.license.lic diff --git a/shandan-bianmu/src/main/java/com/keyware/shandan/bianmu/controller/MetadataController.java b/shandan-bianmu/src/main/java/com/keyware/shandan/bianmu/controller/MetadataController.java index 2fbdeb4..aa7d37d 100644 --- a/shandan-bianmu/src/main/java/com/keyware/shandan/bianmu/controller/MetadataController.java +++ b/shandan-bianmu/src/main/java/com/keyware/shandan/bianmu/controller/MetadataController.java @@ -9,6 +9,7 @@ import com.keyware.shandan.bianmu.enums.ReviewStatus; import com.keyware.shandan.bianmu.export.DirectoryExport; import com.keyware.shandan.bianmu.export.ExportCache; import com.keyware.shandan.bianmu.export.ExportProgress; +import com.keyware.shandan.bianmu.mapper.DirectoryResourceMapper; import com.keyware.shandan.bianmu.service.DataLabelsService; import com.keyware.shandan.bianmu.service.DirectoryMetadataService; import com.keyware.shandan.bianmu.service.MetadataService; @@ -55,7 +56,8 @@ public class MetadataController extends BaseController page(HashMap param) { + public Result page(Authentication auth,HashMap param) { + Page resultData = getMetadataBasicVoPage(param); + return Result.of(resultData); + } + @PostMapping("/simple/export") + public Result export(Authentication auth,HashMap param) { + Page resultData = getMetadataBasicVoPage(param); + List directoryResourceList = new ArrayList<>(); + resultData.getRecords().stream().forEach(metadataBasicVo -> { + DirectoryResource directoryResource = new DirectoryResource(); + directoryResource.setId(metadataBasicVo.getId()); + directoryResource.setDirectoryPath("/资源注册/"+metadataBasicVo.getMetadataName()); + directoryResource.setDataType(metadataBasicVo.getDataType()); + directoryResource.setResourceType("metadata"); + directoryResourceList.add(directoryResource); + }); + Assert.notNull(auth, "用户信息认证失败"); + String userId = auth.getPrincipal().toString(); + // 这个逻辑只允许同一个用户同时只能有一个导出任务 + ExportProgress export = ExportCache.getCache(userId, null); + if (export == null) { + // 查询数据 + export = new DirectoryExport(userId, directoryResourceList); + ExportCache.startExport(export); + } + return Result.of(resultData); + } + /** + * 抽取出分页查询方法 共用于数据导出 + * @param param + * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page + * @author YaoJz + * @date 2024/04/17 10:14 + */ + private Page getMetadataBasicVoPage(HashMap param) { int current = (int) param.getOrDefault("current", "1"); int size = (int) param.getOrDefault("size", "10"); String metadataName = (String) param.getOrDefault("metadataName", ""); String reviewStatus = (String) param.getOrDefault("reviewStatus", ""); String useStatus = (String) param.getOrDefault("useStatus", ""); - MetadataBasicVo metadata = new MetadataBasicVo(); if (StringUtils.hasText(metadataName)) { metadata.setMetadataName(metadataName); @@ -83,7 +118,6 @@ public class MetadataController extends BaseController query = new QueryWrapper<>(metadata); if (StringUtils.hasText(useStatus)) { Collection ids = new ArrayList<>(); @@ -99,7 +133,7 @@ public class MetadataController extends BaseController { item.setUsed(ids.contains(item.getId())); }).toList(); - return Result.of(resultData); + return resultData; } @GetMapping("/edit") diff --git a/shandan-bianmu/src/main/resources/static/js/business/metadata/metadata.js b/shandan-bianmu/src/main/resources/static/js/business/metadata/metadata.js index 75a9962..4dc6fe6 100644 --- a/shandan-bianmu/src/main/resources/static/js/business/metadata/metadata.js +++ b/shandan-bianmu/src/main/resources/static/js/business/metadata/metadata.js @@ -15,7 +15,7 @@ layui.use(['layer', 'listPage', 'form', 'dict'], function () { let where = {metadataName: '', reviewStatus: '', useStatus: ''}; const fieldMap = new Map() - METADATA_FORM_CONFIG.forEach(conf=>fieldMap.set(conf.fieldName, conf)); + METADATA_FORM_CONFIG.forEach(conf => fieldMap.set(conf.fieldName, conf)); console.info(fieldMap); const listPage = layui.listPage.init({ deleteUrl: `${ctx}/business/metadata/delete`, @@ -34,7 +34,7 @@ layui.use(['layer', 'listPage', 'form', 'dict'], function () { templet: data => `${data.metadataName}` }, - {field: 'metadataComment', title: '中文注释',hide: fieldMap.get('metadataName').isShow}, + {field: 'metadataComment', title: '中文注释', hide: fieldMap.get('metadataName').isShow}, { field: 'secretLevel', title: '密级', @@ -49,7 +49,13 @@ layui.use(['layer', 'listPage', 'form', 'dict'], function () { width: 100, templet: data => layui.dict.getDictDesc('data_source', data.dataFrom) }, - {field: 'collectionTime', title: '任务时间', width: 180, align: 'center',hide: !fieldMap.get('collectionTime').isShow}, + { + field: 'collectionTime', + title: '任务时间', + width: 180, + align: 'center', + hide: !fieldMap.get('collectionTime').isShow + }, { field: 'used', title: '关联状态', width: 120, align: 'center', templet: (data) => { if (data.used) { @@ -186,7 +192,17 @@ layui.use(['layer', 'listPage', 'form', 'dict'], function () { }) }) }); + //导出文件 + listPage.addTableRowEvent('export', (data) => { + let param = { + current: listPage.table.index, + size: listPage.table.limit, + metadataName: where.metadataName + }; + console.log("系统异常 文件导出导出导出出",param,listPage) + Util.exportResource('/business/metadata/simple/export', param) + }); listPage.addTableRowEvent('batchCommit', (data) => { let checkRows = listPage.getCheckStatus(); let datas = checkRows.data; diff --git a/shandan-bianmu/src/main/resources/view/business/metadata/metadata.html b/shandan-bianmu/src/main/resources/view/business/metadata/metadata.html index c1f9075..190cdd2 100644 --- a/shandan-bianmu/src/main/resources/view/business/metadata/metadata.html +++ b/shandan-bianmu/src/main/resources/view/business/metadata/metadata.html @@ -28,6 +28,7 @@
+ diff --git a/shandan-browser/pom.xml b/shandan-browser/pom.xml index a35bef2..fa5290d 100644 --- a/shandan-browser/pom.xml +++ b/shandan-browser/pom.xml @@ -56,6 +56,18 @@ shandan-system 1.0.0 + + + e-iceblue + spire.doc.free + 5.2.0 + + + + + + + diff --git a/shandan-browser/src/main/java/com/keyware/shandan/BrowserApplication.java b/shandan-browser/src/main/java/com/keyware/shandan/BrowserApplication.java index 5316fae..230cb2c 100644 --- a/shandan-browser/src/main/java/com/keyware/shandan/BrowserApplication.java +++ b/shandan-browser/src/main/java/com/keyware/shandan/BrowserApplication.java @@ -1,6 +1,7 @@ package com.keyware.shandan; import com.keyware.shandan.browser.SearchLogProcessor; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/CustomFormController.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/CustomFormController.java new file mode 100644 index 0000000..6bdfaa5 --- /dev/null +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/CustomFormController.java @@ -0,0 +1,91 @@ +package com.keyware.shandan.browser.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.keyware.shandan.bianmu.entity.DirectoryResource; +import com.keyware.shandan.bianmu.export.DirectoryExport; +import com.keyware.shandan.bianmu.export.ExportCache; +import com.keyware.shandan.bianmu.export.ExportProgress; +import com.keyware.shandan.bianmu.mapper.DirectoryResourceMapper; +import com.keyware.shandan.browser.entity.CustomForm; +import com.keyware.shandan.browser.entity.SearchConditionVo; +import com.keyware.shandan.browser.service.CustomFormService; +import com.keyware.shandan.common.entity.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.*; + +import javax.json.Json; +import javax.json.JsonObject; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author YaoJz + * @description + * 制式表格 控制类 + * @date 2024/4/18 17:30 + */ +@RestController +@RequestMapping("/CustomForm") +public class CustomFormController { + + @Autowired + CustomFormService customFormService; + @Autowired + private DirectoryResourceMapper directoryResourceMapper; + /** + * 创建制式表格 + * @param customForm + * @return com.keyware.shandan.common.entity.Result + * @author YaoJz + * @date 2024/04/18 17:43 + */ + @PostMapping("/create") + public Result createCustomForm(CustomForm customForm) { + String fieldConfig = JSON.toJSONString(customForm.getFieldList()); + customForm.setFieldConfig(fieldConfig); + return Result.of( customFormService.save(customForm)); + } + @GetMapping("/list") + public Result listCustomForm() { + return Result.of( customFormService.list()); + } + @GetMapping("/getOne/{id}") + public Result getCustomForm(@PathVariable String id) { + return Result.of( customFormService.getById(id)); + } + @PostMapping("/updata") + public Result updataCustomForm(CustomForm customForm) { + return Result.of( customFormService.updateById(customForm)); + } + @GetMapping("/delete") + public Result deleteCustomForm(@PathVariable String id) { + return Result.of( customFormService.removeById(id)); + } + @PostMapping("/export/{customFormId}") + public Result exportCustomForm(@PathVariable String customFormId, Authentication auth) { + CustomForm customForm = customFormService.getById(customFormId); + HashMap map = new HashMap<>(); + map.put("fieldConfig",customForm.getFieldConfig()); + map.put("otherContext",customForm.getOtherContext()); + DirectoryResource resource = directoryResourceMapper.selectById(customForm.getMetaId()); + resource.setIsCustom(true); + resource.setCustomConfigMap(map); + List directoryResourceList = new ArrayList<>(); + directoryResourceList.add(resource); + Assert.notNull(auth, "用户信息认证失败"); + String userId = auth.getPrincipal().toString(); + // 这个逻辑只允许同一个用户同时只能有一个导出任务 + ExportProgress export = ExportCache.getCache(userId, null); + if (export == null) { + // 查询数据 + export = new DirectoryExport(userId, directoryResourceList); + ExportCache.startExport(export); + } + return null; + } +} diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/SearchController.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/SearchController.java index 7a19f62..8aa9b1b 100644 --- a/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/SearchController.java +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/SearchController.java @@ -271,7 +271,6 @@ public class SearchController { Assert.notNull(auth, "用户信息认证失败"); MetadataBasicVo metadata = metadataService.getById(metaId); Assert.notNull(metadata, "数据资源表不存在"); - String userId = auth.getPrincipal().toString(); MetaTableExport export = ExportCache.getCache(userId, null); if (export == null) { @@ -280,9 +279,23 @@ public class SearchController { export = newExport; ExportCache.startExport(export); } - return Result.of(export.getProgress()); } + @PostMapping("/export/metadata/{metaId}/{type}") + public Result exportMetadata(@PathVariable String metaId,@PathVariable String type, SearchConditionVo condition, Authentication auth) { + Assert.notNull(auth, "用户信息认证失败"); + MetadataBasicVo metadata = metadataService.getById(metaId); + Assert.notNull(metadata, "数据资源表不存在"); + String userId = auth.getPrincipal().toString(); + MetaTableExport export = ExportCache.getCache(userId, null); + if (export == null) { + MetaTableExport newExport = new MetaTableExport(userId, metadata,type); + newExport.setQueryHandler((list) -> list.addAll(metadataDataService.list(metadata, condition))); + export = newExport; + ExportCache.startExport(export); + } + return Result.of(export.getProgress()); + } /** * 目录数据导出-查询任务状态 @@ -317,7 +330,8 @@ public class SearchController { if (export == null) { return "错误:导出任务不存在"; } - String path = export.getDownloadPath(); +// String path = export.getDownloadPath(); + String path = export.tranType(); String downloadName = FileUtil.getName(path); File file = new File(path); return FileDownload.download(response, file, downloadName, true); diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/entity/CustomForm.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/entity/CustomForm.java new file mode 100644 index 0000000..7401d7c --- /dev/null +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/entity/CustomForm.java @@ -0,0 +1,43 @@ +package com.keyware.shandan.browser.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; +import java.io.Serializable; +import java.util.List; + +import com.baomidou.mybatisplus.annotation.TableName; + +import javax.validation.constraints.NotNull; + +/** + * @author YaoJz + * @description + * @date 2024/4/18 16:59 + */ +@Data +@TableName("CUSTOM_FORM") +public class CustomForm implements Serializable { + private static final long serialVersionUID = 7552053530616826540L; + @TableId("ID") + private Integer id; + + @NotNull + private List fieldList; + @TableField("METAID") + @NotNull + private String metaId; + @TableField("OTHERCONTEXT") + private String otherContext; + @TableField("FORMID") + private String formId; + @TableField("FIELD_CONFIG") + private String fieldConfig; + +} +@Data +class CustFormFormat{ + private String fieldKey; + private String fieldName; + private String fieldIndex; +} \ No newline at end of file diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/mapper/CustomFormMapper.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/mapper/CustomFormMapper.java new file mode 100644 index 0000000..509ed47 --- /dev/null +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/mapper/CustomFormMapper.java @@ -0,0 +1,15 @@ +package com.keyware.shandan.browser.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.keyware.shandan.browser.entity.CustomForm; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +/** + * @author YaoJz + * @description + * @date 2024/4/18 17:41 + */ +@Mapper +public interface CustomFormMapper extends BaseMapper { +} diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/service/CustomFormService.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/service/CustomFormService.java new file mode 100644 index 0000000..6711488 --- /dev/null +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/service/CustomFormService.java @@ -0,0 +1,14 @@ +package com.keyware.shandan.browser.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.keyware.shandan.browser.entity.CustomForm; +import com.keyware.shandan.common.service.IBaseService; + +/** + * @author YaoJz + * @description + * @date 2024/4/18 17:34 + */ +public interface CustomFormService extends IService { + String checkArg(CustomForm customForm); +} diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/service/impl/CustomFormServiceImpl.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/service/impl/CustomFormServiceImpl.java new file mode 100644 index 0000000..175030f --- /dev/null +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/service/impl/CustomFormServiceImpl.java @@ -0,0 +1,20 @@ +package com.keyware.shandan.browser.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.keyware.shandan.browser.entity.CustomForm; +import com.keyware.shandan.browser.mapper.CustomFormMapper; +import com.keyware.shandan.browser.service.CustomFormService; +import org.springframework.stereotype.Service; + +/** + * @author YaoJz + * @description + * @date 2024/4/18 17:37 + */ +@Service +public class CustomFormServiceImpl extends ServiceImpl implements CustomFormService { + @Override + public String checkArg(CustomForm customForm) { + return null; + } +} diff --git a/shandan-browser/src/main/resources/static/css/customForm.css b/shandan-browser/src/main/resources/static/css/customForm.css new file mode 100644 index 0000000..76fbb96 --- /dev/null +++ b/shandan-browser/src/main/resources/static/css/customForm.css @@ -0,0 +1,48 @@ +#layer-content-report { + height: 100% +} + +.report-main { + display: flex; + flex-direction: column; + width: 100%; + height: 100% +} + +.report-main .report-btn-line { + display: flex; + justify-content: flex-end; + padding: 10px 20px; +} + +.sorting-item { + display: flex; + flex-direction: row; + justify-content: space-between; + padding: 5px 0 !important; +} + +.report-main .report-items { + flex-grow: 1; + display: flex; + flex-wrap: wrap; + overflow-y: overlay; + justify-content: space-around; +} + +.echarts-item { + width: 500px; + height: 40%; + padding: 0 20px; +} +.layui-elem-field{border-color: #e8e8e8 !important;} +.layui-elem-field legend { + margin-left: 20px; + padding: 0 10px; + font-size: 16px; + font-weight: 400; + color: #7d7d7d; +} +.layui-field-box { + padding: 15px 50px 15px 15px; +} \ No newline at end of file diff --git a/shandan-browser/src/main/resources/static/js/customForm.js b/shandan-browser/src/main/resources/static/js/customForm.js new file mode 100644 index 0000000..a87077c --- /dev/null +++ b/shandan-browser/src/main/resources/static/js/customForm.js @@ -0,0 +1,113 @@ +/** + * 统计报表组件 + * + * @author GuoXin + * @since 2021/7/12 + */ +const template_configs = ` +
+
asdsssssssasdasd
+ +
+ + +
+`; + +function CustomReportComponent(columns, conditions, metadataId) { + this.metadataId = metadataId || ''; + this.columns = columns || []; + this.conditions = conditions || []; + this.echarts = []; + this.size = 0; + this.formData = {}; + this.form = {}; + this.gtable = {}; + layui.use(['form','gtable'], () => { + this.gtable = layui.gtable; + this.form = layui.form; + }) +} + +function initTable(table) { + var inst = table.render({ + elem: '#ID-table-demo-data', + cols: [[ //标题栏 + {field: 'id', title: 'ID', width: 80, sort: true}, + {field: 'username', title: '名称', width: 120}, + {field: 'sign', title: '顺序', minWidth: 160} + ]], + data: [{ // 赋值已知数据 + "id": "10001", + "username": "张三1", + "sex": "男", + "city": "浙江杭州", + "sign": "人生恰似一场修行", + "experience": "116" + }, { + "id": "10008", + "username": "张三8", + "sex": "男", + "city": "浙江杭州", + "sign": "人生恰似一场修行", + "experience": "106" + }], + page: false, // 是否显示分页 + limits: [5, 10, 15], + // limit: 5 // 每页默认显示的数量 + }); + +} + +function createNewTable(){ + console.log("createNewTable1") + $(`a[name='create']`).on('click', createNewTable); +} +function createTable(){ + console.log("createNewTable2") + $(`a[name='create']`).on('click', createNewTable); +} + +/** + * 打开统计报表主窗口 + */ +CustomReportComponent.prototype.openMainLayer = function () { + const _this = this; + layer.open({ + type: 1, + title: '统计报表', + area: ['900px', '100%'], + content: template_configs, + success: function (layero, index) { + initTable(_this.gtable) + createTable() + }, + + done: function () { + } + }) +} + + +/** + * 打开图表配置窗口 + */ +CustomReportComponent.prototype.openEchartsConfigLayer = function () { + const _this = this; + layer.open({ + title: '统计报表配置', + type: 1, + resize: false, + closeBtn: false, + btn: ['确定', '取消'], + content: template_config, + success: function (layerObj, index) { + _this.renderSelect(); + $('#echartsConfigForm').parent().css('overflow', 'visible') + }, + yes: function (index) { + _this.requestData(() => layer.close(index)); + } + }); +} diff --git a/shandan-browser/src/main/resources/static/js/meta_search.js b/shandan-browser/src/main/resources/static/js/meta_search.js index 1f08531..fce6233 100644 --- a/shandan-browser/src/main/resources/static/js/meta_search.js +++ b/shandan-browser/src/main/resources/static/js/meta_search.js @@ -38,13 +38,26 @@ layui.use(['dropdown', 'gtable', 'laydate', 'form'], function () { toolbar: '#table-title', request: {pageName: 'page', limitName: 'size'}, defaultToolbar: ['filter', { - title: '导出数据', + title: '导出数据(excel)', layEvent: 'exports', icon: 'layui-icon-export' }, { + title: '导出数据(word)', + layEvent: 'exportsWord', + icon: 'layui-icon-export' + }, + { + title: '导出数据(pdf)', + layEvent: 'exportsPdf', + icon: 'layui-icon-export' + },{ title: '统计报表', layEvent: 'tong-ji', icon: 'layui-icon-chart' + }, { + title: '自定义制式表格', + layEvent: 'CustomFormExport', + icon: 'layui-icon-chart' }] }) // 排序事件回调 @@ -60,7 +73,13 @@ layui.use(['dropdown', 'gtable', 'laydate', 'form'], function () { if (event === 'tong-ji') { openStatisticalReport() }else if(event === 'exports'){ - Util.exportResource(`/search/export/metadata/${metadata.id}`, where); + Util.exportResource(`/search/export/metadata/${metadata.id}/excel`, where); + }else if(event === 'exportsPdf'){ + Util.exportResource(`/search/export/metadata/${metadata.id}/pdf`, where); + }else if(event === 'exportsWord'){ + Util.exportResource(`/search/export/metadata/${metadata.id}/word`, where); + }else if (event === 'CustomFormExport'){ + openStatisticalCustomFormReport() } }); }); @@ -257,4 +276,12 @@ layui.use(['dropdown', 'gtable', 'laydate', 'form'], function () { const reportComponent = new ReportComponent(columns, getConditionItemValue(), metadata.id); reportComponent.openMainLayer(); } + + /** + * 打开自定义制式表格 + */ + function openStatisticalCustomFormReport() { + const reportComponent = new CustomReportComponent(columns, getConditionItemValue(), metadata.id); + reportComponent.openMainLayer(); + } }); \ No newline at end of file diff --git a/shandan-browser/src/main/resources/static/js/report.js b/shandan-browser/src/main/resources/static/js/report.js index ec1d0b9..2d01185 100644 --- a/shandan-browser/src/main/resources/static/js/report.js +++ b/shandan-browser/src/main/resources/static/js/report.js @@ -11,7 +11,6 @@ function ReportComponent(columns, conditions, metadataId) { this.echarts = []; this.size = 0; this.formData = {}; - this.form = {}; layui.use(['form'], () => { this.form = layui.form; diff --git a/shandan-browser/src/main/resources/view/CustomFrom.html b/shandan-browser/src/main/resources/view/CustomFrom.html new file mode 100644 index 0000000..cf14cb5 --- /dev/null +++ b/shandan-browser/src/main/resources/view/CustomFrom.html @@ -0,0 +1,127 @@ + + + + + + + + \ No newline at end of file diff --git a/shandan-browser/src/main/resources/view/meta_search.html b/shandan-browser/src/main/resources/view/meta_search.html index 0893401..c0d3364 100644 --- a/shandan-browser/src/main/resources/view/meta_search.html +++ b/shandan-browser/src/main/resources/view/meta_search.html @@ -14,6 +14,15 @@ const metadata = /*[[${metadata}]]*/ {}; const columns = /*[[${columns}]]*/ []; + +
@@ -56,6 +65,7 @@ + diff --git a/shandan-common/src/main/resources/static/js/common/common.js b/shandan-common/src/main/resources/static/js/common/common.js index f535dea..c2dce2c 100644 --- a/shandan-common/src/main/resources/static/js/common/common.js +++ b/shandan-common/src/main/resources/static/js/common/common.js @@ -600,7 +600,9 @@ commonUtil = { exportResource: (url, params)=>{ let layerIndex; showExportMsgLayer('开始准备数据'); + console.log("url params",url ,params) Util.post(url, params, false).then(({flag, data, msg}) => { + console.log("url params",url ,params) if (flag) { showExportMsgLayer(data.msg); queryProgress(data.exportId); diff --git a/shandan-system/pom.xml b/shandan-system/pom.xml index b0d1ffd..e5f1161 100644 --- a/shandan-system/pom.xml +++ b/shandan-system/pom.xml @@ -107,5 +107,11 @@ 2.5.1 + + aspose + words + 14.8.0 + jdk16 + \ No newline at end of file diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java index f3e368f..d3f633f 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/controller/MetadataCommonController.java @@ -181,7 +181,7 @@ public class MetadataCommonController { List records = result.getRecords(); ArrayList list = new ArrayList<>(); for (DirectoryResource directoryResource:records){ - list.add(directoryResource.getDirectoryId()); + list.add(directoryResource.getId()); } List directoryResources = directoryResourceMapper.selectListById(list); Assert.notNull(auth, "用户信息认证失败"); diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/entity/DirectoryResource.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/entity/DirectoryResource.java index c68afb9..0725674 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/entity/DirectoryResource.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/entity/DirectoryResource.java @@ -8,8 +8,10 @@ import com.keyware.shandan.bianmu.enums.ReviewStatus; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; +import javax.json.JsonObject; import java.io.Serializable; import java.util.Date; +import java.util.Map; @Data @TableName("V_DIRECTORY_RESOURCE") @@ -97,4 +99,11 @@ public class DirectoryResource implements Serializable { @TableField(exist = false) private boolean write; + + //为自定义表格添加 是否是自定义表格 主要为导出数据时的判断条件 + @TableField(exist = false) + private Boolean isCustom ; + @TableField(exist = false) + private Map customConfigMap ; + } diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/DirectoryExport.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/DirectoryExport.java index ee5d251..60ffec0 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/DirectoryExport.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/DirectoryExport.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.ZipUtil; import cn.hutool.http.HttpUtil; import cn.hutool.poi.excel.BigExcelWriter; import cn.hutool.poi.excel.ExcelUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.keyware.shandan.bianmu.entity.DirectoryResource; @@ -18,12 +19,10 @@ import com.keyware.shandan.frame.config.component.AppContext; import com.keyware.shandan.system.entity.SysFile; import com.keyware.shandan.system.service.SysFileService; import com.keyware.shandan.system.utils.SysSettingUtil; +import org.elasticsearch.cluster.ClusterState; import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; public class DirectoryExport extends ExportProgress { @@ -48,6 +47,8 @@ public class DirectoryExport extends ExportProgress { dataList.forEach(resource -> { if ("file".equals(resource.getResourceType())) { exportFile(resource); + } else if (resource.getIsCustom() != null && resource.getIsCustom()) { + exportCustomMetadata(resource); } else { exportMetadata(resource); } @@ -90,7 +91,7 @@ public class DirectoryExport extends ExportProgress { * * @param resource 数据资源 */ - private void exportMetadata(DirectoryResource resource) { + private void exportCustomMetadata(DirectoryResource resource) { File serverFile = new File(createResourceDir(resource.getDirectoryPath())); String path = serverFile.getPath() + ".xlsx"; MetadataBasicVo metadata = null; @@ -113,6 +114,71 @@ public class DirectoryExport extends ExportProgress { path = dirPath + File.separator + "(数据读取错误)" + temp.getName(); } + String fieldConfig = resource.getCustomConfigMap().get("fieldConfig"); + JSONArray configobj = JSON.parseArray(fieldConfig); + // 所有行的集合 + List> rowList = new ArrayList<>(); + // 字段列名集合 + String[] colNameArr = new String[configobj.size()]; + // 字段列名注释集合,当做表格的第一行 + List columns =StreamUtil.as(configobj).map(field -> { + JSONObject obj = (JSONObject) field; + String fieldKey = obj.getString("fieldKey"); + String fieldName = obj.getString("fieldName"); + colNameArr[Integer.parseInt(obj.getString("fieldIndex"))] = fieldName; + return fieldName + (StringUtils.hasText(fieldKey) ? "[" + fieldName + "]" : ""); + }).toList(); + List colNameList = Arrays.asList(colNameArr); + // 添加第一行 + rowList.add(columns); + // 遍历数据 + datas.forEach(data -> { + // 遍历字段列名,获取对应数据并拼接成列的集合 + List cells = colNameList.stream().map(col -> { + Object value = data.get(col); + if (value == null) { + return ""; + } + return String.valueOf(value); + }).collect(Collectors.toList()); + rowList.add(cells); + }); + List> rows = CollUtil.newArrayList(rowList); + //通过工具类创建writer + BigExcelWriter writer = ExcelUtil.getBigWriter(path); + //一次性写出内容 + writer.write(rows); + //关闭writer,释放内存 + writer.close(); + } + + /** + * 导出数据表 + * + * @param resource 数据资源 + */ + private void exportMetadata(DirectoryResource resource) { + File serverFile = new File(createResourceDir(resource.getDirectoryPath())); + String path = serverFile.getPath() + ".xlsx"; + MetadataBasicVo metadata = null; + JSONArray colsArray = null; + List> datas = null; + try { + metadata = metadataService.getById(resource.getId()); + colsArray = metadataService.getColumns(metadata.getId()); + datas = metadataService.getDynamicData(metadata); + } catch (Exception e) { + colsArray = new JSONArray(); + JSONObject defaultJson = new JSONObject(); + defaultJson.put("comment", "数据查询失败,无法连接到指定的数据库"); + colsArray.add(defaultJson); + datas = new ArrayList<>(); + + File temp = new File(path); + String dirPath = temp.getParentFile().getPath(); + path = dirPath + File.separator + "(数据读取错误)" + temp.getName(); + } + // 所有行的集合 List> rowList = new ArrayList<>(); // 字段列名集合 @@ -183,4 +249,9 @@ public class DirectoryExport extends ExportProgress { public String getDownloadPath() { return zipName; } + + @Override + public String tranType() { + return null; + } } diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/ExportProgress.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/ExportProgress.java index b9c370a..ae267ef 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/ExportProgress.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/ExportProgress.java @@ -37,6 +37,7 @@ public abstract class ExportProgress implements Runnable, Serializable { public abstract long getStepTotal(); public abstract String getDownloadPath(); + public abstract String tranType(); /** * 偏移量自增 diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/FileSearchExport.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/FileSearchExport.java index 0606399..bc08b5d 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/FileSearchExport.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/FileSearchExport.java @@ -188,4 +188,9 @@ public class FileSearchExport extends ExportProgress { return zipName; } + @Override + public String tranType() { + return null; + } + } diff --git a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/MetaTableExport.java b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/MetaTableExport.java index 6205955..9725b3e 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/MetaTableExport.java +++ b/shandan-system/src/main/java/com/keyware/shandan/bianmu/export/MetaTableExport.java @@ -13,9 +13,17 @@ import com.keyware.shandan.frame.config.component.AppContext; import com.keyware.shandan.system.entity.SysOrg; import com.keyware.shandan.system.entity.SysUser; import com.keyware.shandan.system.service.SysUserService; +import com.keyware.shandan.system.utils.Word2PdfAsposeUtil; import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.xwpf.usermodel.ParagraphAlignment; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableCell; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -36,6 +44,8 @@ public class MetaTableExport extends ExportProgress { private final List> datas = new ArrayList<>(); private Consumer>> queryHandler; private boolean isDone = false; + //新添加 导出 + private String type; public MetaTableExport(String userId, MetadataBasicVo metadata) { super(userId); @@ -49,6 +59,18 @@ public class MetaTableExport extends ExportProgress { fileName = tempDir + File.separator + name + ".xlsx"; } + public MetaTableExport(String userId, MetadataBasicVo metadata,String type) { + super(userId); + this.userService = AppContext.getContext().getBean(SysUserService.class); + this.metadataService = AppContext.getContext().getBean(MetadataService.class); + this.metadata = metadata; + String name = metadata.getMetadataComment(); + if (!StringUtils.hasText(name)) { + name = metadata.getMetadataName(); + } + fileName = tempDir + File.separator + name + ".xlsx"; + this.type=type; + } @Override public void run() { this.setTitle("正在读取数据表信息"); @@ -65,36 +87,23 @@ public class MetaTableExport extends ExportProgress { JSONObject field = (JSONObject) json; return field.getString("comment"); }).collect(Collectors.toList())); - - try { this.setTitle("正在查询数据"); this.autoAddStep(); this.queryHandler.accept(this.datas); handleResult(); - - File file = new File(fileName); if (file.exists()) { file.delete(); } List> rows = CollUtil.newArrayList(rowList); - //通过工具类创建writer - BigExcelWriter writer = ExcelUtil.getBigWriter(file); - - this.setTitle("正在写入缓存"); - this.autoAddStep(); - // 添加表头 - addTableHeader(writer); - //一次性写出内容 - writer.write(rows, true); - - this.setTitle("正在写入文件"); - this.autoAddStep(); - //写入文件后关闭writer,释放内存 - writer.close(); - - this.autoAddStep(); + if (type==null||"excel".equals(type)){ + excelExport(fileName, rows); + }else if ("word".equals(type)){ + wordExport(fileName, rows); + }else if("pdf".equals(type)){ + pdfExport(fileName, rows); + } this.setTitle("数据文件准备完毕,开始下载"); isDone = true; } catch (Exception e) { @@ -105,6 +114,33 @@ public class MetaTableExport extends ExportProgress { } } + /** + * excel导出 + * @param fileName + * @param rows + * @author YaoJz + * @date 2024/04/23 10:44 + */ + private void excelExport(String fileName, List> rows) { + File file = new File(fileName); + //通过工具类创建writer + BigExcelWriter writer = ExcelUtil.getBigWriter(file); + + this.setTitle("正在写入缓存"); + this.autoAddStep(); + // 添加表头 + addTableHeader(writer); + //一次性写出内容 + writer.write(rows, true); + + this.setTitle("正在写入文件"); + this.autoAddStep(); + //写入文件后关闭writer,释放内存 + writer.close(); + + this.autoAddStep(); + } + private void addTableHeader(BigExcelWriter writer) { SysUser user = userService.getById(getUserId()); SysOrg org = user.getOrg(); @@ -138,6 +174,20 @@ public class MetaTableExport extends ExportProgress { return this.fileName; } + /** + * 文件类型转换 转换后缀名 + * @return java.lang.String + * @author YaoJz + * @date 2024/04/23 12:42 + */ + @Override + public String tranType(){ + switch (type){ + case "word": return this.fileName.replace(".xlsx", ".docx"); + case "pdf": return this.fileName.replace(".xlsx", ".pdf"); + default: return this.fileName; + } + } public void handleResult() { for (Map data : this.datas) { // 遍历字段列名,获取对应数据并拼接成列的集合 @@ -158,4 +208,208 @@ public class MetaTableExport extends ExportProgress { public boolean getIsDone() { return isDone; } + + + + + + public static void main(String[] args) { + test(); + } + + public void pdfExport(String fileName, List> rows){ + wordExport(fileName,rows); + String wordPath = fileName.replace(".xlsx", ".docx"); + String pdfPath = fileName.replace(".xlsx", ".pdf"); + Word2PdfAsposeUtil.doc2pdf(wordPath,pdfPath); + } + public void wordExport(String fileName, List> rows){ + + // 1.创建一个新的Word文档 + XWPFDocument document = new XWPFDocument(); + FileOutputStream fos = null; + try { + // 2.创建一个新的表格 + int cols=0; + + if (rows.get(0)!=null){ + cols=rows.get(0).size(); + } + XWPFTable table = document.createTable(rows.size(), cols); + // 3.设置表格样式 + table.getCTTbl().addNewTblPr().addNewTblStyle().setVal("Table Grid"); + table.setWidth(10); // 设置表格宽度为100% + // 4.填充表格内容 + XWPFTableCell cell = null; + for (int row = 0; row < rows.size(); row++) { // 循环遍历表格的行 + for (int col = 0; col < cols; col++) { // 循环遍历表格的列 + // 获取当前单元格 + cell = table.getRow(row).getCell(col); + // 设置单元格内容垂直居中 + cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); + // 设置单元格内容水平居中(获取单元格中的第一个段落对象) + cell.getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER); + // 设置单元格内容 + cell.setText(rows.get(row).get(col)); + } + } + // 保存文档 + // 输出流,用于将文档写入磁盘 + String wordPath = fileName.replace(".xlsx", ".docx"); + fos = new FileOutputStream(wordPath); + // 将文档写入输出流 + document.write(fos); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (fos != null) { + try { + // 关闭输出流 + fos.close(); + if (document != null) { + // 关闭Word文档 + document.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + public static void test() { + // 1.创建一个新的Word文档 + XWPFDocument document = new XWPFDocument(); + FileOutputStream fos = null; + try { + // 2.创建一个新的表格,11行7列 + XWPFTable table = document.createTable(11, 7); + + // 3.设置表格样式 + table.getCTTbl().addNewTblPr().addNewTblStyle().setVal("Table Grid"); + table.setWidth(100); // 设置表格宽度为100% + + // 4.填充表格内容 + XWPFTableCell cell = null; + for (int row = 0; row < 11; row++) { // 循环遍历表格的行 + for (int col = 0; col < 7; col++) { // 循环遍历表格的列 + // 获取当前单元格 + cell = table.getRow(row).getCell(col); + // 设置单元格内容垂直居中 + cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); + // 设置单元格内容水平居中(获取单元格中的第一个段落对象) + cell.getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER); + // 设置单元格内容 + cell.setText("行 " + (row + 1) + ", 列 " + (col + 1)); + } + } + + /** + + // 5.合并单元格方式一 // 5.1 合并第1行的第2列到第4列 + table.getRow(0).getCell(1).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); + table.getRow(0).getCell(2).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); + table.getRow(0).getCell(3).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); + + // 5.2 合并第1列的第3行到第4行 + table.getRow(2).getCell(0).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); + table.getRow(3).getCell(0).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); + + // 5.3 合并第4行第4列、第5列、第5行第4列、第5列为一个单元格 // 5.3.1 合并第4行的第4列到第5列 + table.getRow(3).getCell(3).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); + table.getRow(3).getCell(4).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); + // 5.3.2 合并第5行的第4列到第5列 + table.getRow(4).getCell(3).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); + table.getRow(4).getCell(4).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); + // 5.3.3 合并第4列的第4行到第5行 + table.getRow(3).getCell(3).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); + table.getRow(4).getCell(3).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); + + **/ + + // 6.合并单元格方式二(推荐) + // 6.1 水平合并第1行的第2列到第4列 + mergeCellsByHorizontal(table, 0, 1, 3); + // 6.2 垂直合并第1列的第3行到第4行 + mergeCellsByVertically(table, 0, 2, 3); + // 6.3 合并第4行第4列、第5列、第5行第4列、第5列为一个单元格 + // 6.3.1 合并第4行的第4列到第5列 + mergeCellsByHorizontal(table, 3, 3, 4); + // 6.3.2 合并第5行的第4列到第5列 + mergeCellsByHorizontal(table, 4, 3, 4); + // 6.3.3 合并第4列的第4行到第5行 + mergeCellsByVertically(table, 3, 3, 4); + + // 保存文档 + // 输出流,用于将文档写入磁盘 + fos = new FileOutputStream("D:\\testwordexport\\test.docx"); + // 将文档写入输出流 + document.write(fos); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (fos != null) { + try { + // 关闭输出流 + fos.close(); + if (document != null) { + // 关闭Word文档 + document.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + Word2PdfAsposeUtil.doc2pdf("D:\\testwordexport\\test.docx","D:\\testwordexport\\test.pdf"); + System.out.println("Word文档生成成功!"); + } + + // ==================== private method ==================== + /** + *
描述:水平方向合并单元格
+ * @param table 表格 + * @param rowIndex 合并列所在的行下标(从0开始) + * @param startCellIndex 开始合并的列下标(从0开始) + * @param endCellIndex 结束合并的列下标(从0开始) + */ + private static void mergeCellsByHorizontal(XWPFTable table, int rowIndex, int startCellIndex, int endCellIndex) { + String str = ""; + for (int i = startCellIndex; i <= endCellIndex; i++) { + XWPFTableCell cell = table.getRow(rowIndex).getCell(i); + str = "table.getRow("+rowIndex+").getCell("+i+")"; + if (i == startCellIndex) { + // The first merged cell is set with RESTART merge value + cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART); + System.out.println(str + ".getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);"); + } else { + // Cells which join (merge) the first one, are set with CONTINUE + cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE); + System.out.println(str + ".getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);"); + } + } + } + + /** + *
描述:垂直方向合并单元格
+ * @param table 表格 + * @param columnIndex 合并行所在列下标(从0开始) + * @param startCell 开始合并的行下标(从0开始) + * @param endCell 结束合并的行下标(从0开始) + */ + private static void mergeCellsByVertically(XWPFTable table, int columnIndex, int startRowIndex, int endRowIndex) { + String str = ""; + for (int i = startRowIndex; i <= endRowIndex; i++) { + XWPFTableCell cell = table.getRow(i).getCell(columnIndex); + str = "table.getRow("+i+").getCell("+columnIndex+")"; + if (i == startRowIndex) { + // The first merged cell is set with RESTART merge value + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); + System.out.println(str + ".getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);"); + } else { + // Cells which join (merge) the first one, are set with CONTINUE + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); + System.out.println(str + ".getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);"); + } + } + } } diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java b/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java index 1c2f000..aeb9148 100644 --- a/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java +++ b/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java @@ -20,7 +20,6 @@ import com.keyware.shandan.system.service.SysFormConfigService; import com.keyware.shandan.system.service.SysSettingService; import com.keyware.shandan.system.utils.DictUtil; import com.keyware.shandan.system.utils.FileChunkUploadUtil; -import lombok.val; import net.sourceforge.pinyin4j.PinyinHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.Assert; diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/utils/Word2PdfAsposeUtil.java b/shandan-system/src/main/java/com/keyware/shandan/system/utils/Word2PdfAsposeUtil.java new file mode 100644 index 0000000..739092a --- /dev/null +++ b/shandan-system/src/main/java/com/keyware/shandan/system/utils/Word2PdfAsposeUtil.java @@ -0,0 +1,82 @@ +package com.keyware.shandan.system.utils; + +import com.aspose.words.Document; +import com.aspose.words.License; +import com.aspose.words.SaveFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * @BelongsProject: xscan + * @BelongsPackage: com.keyware.xscan.util + * @Author: yaojz + * @CreateTime: 2022-08-05 13:59 + * @Description: TODO + * @Version: *** + */ +public class Word2PdfAsposeUtil { + private static final Logger logger = LoggerFactory.getLogger(Word2PdfAsposeUtil.class); + /** + * + * @return + */ + public static boolean getLicense() { + boolean result = false; + InputStream is = null; + try { + Resource resource = new ClassPathResource("Aspose.license.lic"); + is = resource.getInputStream(); + License aposeLic = new License(); + aposeLic.setLicense(is); + result = true; + } catch (Exception e) { + logger.error("获取许可证异常...",e); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + logger.error("关闭流异常...",e); + } + } + } + return result; + } + /** + * @return boolean + * @Param [inPath, outPath] + **/ + public static boolean doc2pdf(String inPath, String outPath) { +// 验证License 若不验证则转化出的pdf文档会有水印产生 + if (!getLicense()) { + return false; + } + File file = new File(outPath); +// FileOutputStream os = null; + try(FileOutputStream osStream = new FileOutputStream(file) ) { + long old = System.currentTimeMillis(); + // 新建一个空白pdf文档 + // Address是将要被转化的word文档 + Document doc = new Document(inPath); + // 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, + doc.save(osStream, SaveFormat.PDF); + osStream.flush(); + osStream.close(); + // EPUB, XPS, SWF 相互转换 + long now = System.currentTimeMillis(); + // 转化用时 + System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); + } catch (Exception e) { + logger.error("pdf转换失败...",e); + return false; + } + return true; + } +} diff --git a/shandan-system/src/main/resources/Aspose.license.lic b/shandan-system/src/main/resources/Aspose.license.lic new file mode 100644 index 0000000..3117434 --- /dev/null +++ b/shandan-system/src/main/resources/Aspose.license.lic @@ -0,0 +1,20 @@ + + +iMedRIS Data Corporation +whs@imedris.com +Developer OEM +Limited to 1 developer, unlimited physical locations +190103154649 +289601 +This is a redistributable license + +Aspose.Total for Java + +Enterprise +7f645a78-5687-4fad-ab7f-9b4141651d27 +20200403 +3.0 +https://purchase.aspose.com/policies/use-license + +cqB2T9ic/d8/1ICIPO2PoYfvwQaljWeY3om8xXMo4zllu3h/xL1CbF8iFc6xk1RXXq2UOd3XKfJL9QnoRtjm3IHod2iINB+DC1lolh5GumiJkR/C8oighnumtCIDJHZyEQvyAK1oqELhTWVlLcpyXOkIwdhXDI6l4/uhptYGz3E= + \ No newline at end of file