Commit b564dd87 authored by wangyangyang's avatar wangyangyang

文档 图册:自动任务生成图册目录

parent 17425ac1
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.4</version>
</dependency>
<dependency> <dependency>
<groupId>com.yonde.dcs</groupId> <groupId>com.yonde.dcs</groupId>
<artifactId>dcs-doc-expand-feign</artifactId> <artifactId>dcs-doc-expand-feign</artifactId>
......
...@@ -9,6 +9,8 @@ import com.yonde.dcs.document.core.util.ResourceHelper; ...@@ -9,6 +9,8 @@ import com.yonde.dcs.document.core.util.ResourceHelper;
* @createTime 2021/09/02 11:30:00 * @createTime 2021/09/02 11:30:00
*/ */
public class Constants { public class Constants {
/** /**
* 主内容 * 主内容
*/ */
...@@ -410,5 +412,5 @@ public class Constants { ...@@ -410,5 +412,5 @@ public class Constants {
/** /**
* app 内部名称 * app 内部名称
*/ */
public static final String APPLICATION_INNER_NAME="dcs-doc"; public static final String APPLICATION_DOC_INNER_NAME ="dcs-doc";
} }
...@@ -3,6 +3,7 @@ package com.yonde.dcs.document.core.controller; ...@@ -3,6 +3,7 @@ package com.yonde.dcs.document.core.controller;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.yonde.dcs.document.core.service.ExtAutoTaskService; import com.yonde.dcs.document.core.service.ExtAutoTaskService;
import com.yonde.dcs.document.core.service.ExtSendFormLinkService; import com.yonde.dcs.document.core.service.ExtSendFormLinkService;
import com.yonde.dcs.document.core.service.expand.ExtDxDocumentService;
import com.yonde.dcs.document.core.util.ExtDocUtil; import com.yonde.dcs.document.core.util.ExtDocUtil;
import com.yonde.dcs.document.common.vo.ExtApplicantVO; import com.yonde.dcs.document.common.vo.ExtApplicantVO;
import com.yonde.dcs.document.common.vo.ExtAuditObjectVO; import com.yonde.dcs.document.common.vo.ExtAuditObjectVO;
...@@ -58,6 +59,17 @@ public class ExtAutoTaskController { ...@@ -58,6 +59,17 @@ public class ExtAutoTaskController {
@Autowired @Autowired
private ExtSendFormLinkService sendFormLinkService; private ExtSendFormLinkService sendFormLinkService;
@Autowired
private ExtDxDocumentService extDxDocumentService;
@ApiOperation("生成图册目录")
@GetMapping({"/catalog"})
public ApiResult generateCatalog(@RequestParam Long docId) {
return ApiResult.ok(extDxDocumentService.generateCatalog(docId), "查询成功");
}
@ApiOperation("电子签名") @ApiOperation("电子签名")
@PostMapping({"/esign"}) @PostMapping({"/esign"})
public ApiResult esign(@RequestBody IdVO entity) { public ApiResult esign(@RequestBody IdVO entity) {
......
...@@ -35,6 +35,13 @@ public class ExtDxDocumentController<V extends DxDocumentVO, S extends ExtDxDocu ...@@ -35,6 +35,13 @@ public class ExtDxDocumentController<V extends DxDocumentVO, S extends ExtDxDocu
return ApiResult.ok(service.getDocAndFolder(dxContextId, parentId), "查询成功"); return ApiResult.ok(service.getDocAndFolder(dxContextId, parentId), "查询成功");
} }
@ApiOperation("生成图册目录")
@GetMapping({"/catalog"})
public ApiResult generateCatalog(@RequestParam Long docId) {
return ApiResult.ok(service.generateCatalog(docId), "查询成功");
}
} }
package com.yonde.dcs.document.core.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = false)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExtCatalogExcelVO {
@ExcelProperty(value = {"图册目录", "序号"})
// @ColumnWidth(20)
private String index;
/**
* 图号 动态属性
*/
@ExcelProperty(value = {"图册目录", "图号"})
// @ColumnWidth(20)
private String drawNumber;
/**
* 名称 基本属性
*/
@ExcelProperty(value = {"图册目录", "图名"})
// @ColumnWidth(20)
private String name;
/**
* 图幅 动态属性
*/
@ExcelProperty(value = {"图册目录", "幅面规格"})
// @ColumnWidth(20)
private String pictureFrame;
/**
* 大版本号 基本属性
*/
@ExcelProperty(value = {"图册目录", "版本"})
// @ColumnWidth(20)
private String versionKey;
}
...@@ -26,4 +26,10 @@ public interface ExtDxDocumentService<V extends DxDocumentVO> extends ExtDxDocum ...@@ -26,4 +26,10 @@ public interface ExtDxDocumentService<V extends DxDocumentVO> extends ExtDxDocum
*/ */
Map<String, DxPageImpl> getDocAndFolder(Long dxContextId, Long parentId); Map<String, DxPageImpl> getDocAndFolder(Long dxContextId, Long parentId);
/**
* 生成图册目录
* @param docId
* @return
*/
DxDocumentVO generateCatalog(Long docId);
} }
...@@ -970,7 +970,7 @@ public class ExtDocServiceImpl implements ExtDocService { ...@@ -970,7 +970,7 @@ public class ExtDocServiceImpl implements ExtDocService {
public Long getBucketId(){ public Long getBucketId(){
DxApplicationVO applicationVO = feignService.findApplicationByInnerName(Constants.APPLICATION_INNER_NAME); DxApplicationVO applicationVO = feignService.findApplicationByInnerName(Constants.APPLICATION_DOC_INNER_NAME);
if(!ObjectUtils.isEmpty(applicationVO)){ if(!ObjectUtils.isEmpty(applicationVO)){
return Long.valueOf(applicationVO.getBucketId()); return Long.valueOf(applicationVO.getBucketId());
} }
......
package com.yonde.dcs.document.core.service.impl.expand; package com.yonde.dcs.document.core.service.impl.expand;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.yonde.dcs.document.common.vo.ExtAtlasDrawingLinkVO;
import com.yonde.dcs.document.core.excel.ExtCatalogExcelVO;
import com.yonde.dcs.document.core.service.ExtDxDocumentFolderService; import com.yonde.dcs.document.core.service.ExtDxDocumentFolderService;
import com.yonde.dcs.document.core.service.expand.ExtDxDocumentService; import com.yonde.dcs.document.core.service.expand.ExtDxDocumentService;
import com.yonde.dcs.document.core.event.DocumentEvent; import com.yonde.dcs.document.core.event.DocumentEvent;
import com.yonde.dcs.document.core.util.*;
import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dex.basedata.data.search.SearchItem; import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryBuilder; import com.yonde.dex.basedata.data.search.SearchQueryBuilder;
import com.yonde.dex.basedata.data.search.SearchQueryCondition; import com.yonde.dex.basedata.data.search.SearchQueryCondition;
import com.yonde.dex.basedata.entity.data.DxPageImpl; import com.yonde.dex.basedata.entity.data.DxPageImpl;
import com.yonde.dex.basedata.entity.data.VersionRelationType; import com.yonde.dex.basedata.entity.data.OperatorType;
import com.yonde.dex.configspec.SpecSearch; import com.yonde.dex.configspec.SpecSearch;
import com.yonde.dex.dfs.feign.FileManagerFeignService;
import com.yonde.dex.dfs.vo.RepoFileVO;
import lombok.SneakyThrows;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.util.*; import java.util.*;
import com.yonde.dcs.document.common.entity.vo.DxDocumentVO; import com.yonde.dcs.document.common.entity.vo.DxDocumentVO;
...@@ -20,6 +33,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -20,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
import com.yonde.dcs.document.core.repository.DocumentRepository; import com.yonde.dcs.document.core.repository.DocumentRepository;
import com.yonde.dcs.document.entity.po.DxDocument; import com.yonde.dcs.document.entity.po.DxDocument;
import com.yonde.dcs.document.core.service.impl.DocumentServiceImpl; import com.yonde.dcs.document.core.service.impl.DocumentServiceImpl;
import org.springframework.web.multipart.MultipartFile;
/** /**
* @description: DxDocument-ServiceImpl * @description: DxDocument-ServiceImpl
...@@ -42,6 +56,9 @@ public class ExtDxDocumentServiceImpl<V extends DxDocumentVO> extends DocumentSe ...@@ -42,6 +56,9 @@ public class ExtDxDocumentServiceImpl<V extends DxDocumentVO> extends DocumentSe
@Autowired @Autowired
private DocumentEvent documentEvent; private DocumentEvent documentEvent;
@Autowired
private FileManagerFeignService fileManagerFeignService;
@Override @Override
public void beforeSave(Collection<V> target) { public void beforeSave(Collection<V> target) {
for (V v : target) { for (V v : target) {
...@@ -92,6 +109,46 @@ public class ExtDxDocumentServiceImpl<V extends DxDocumentVO> extends DocumentSe ...@@ -92,6 +109,46 @@ public class ExtDxDocumentServiceImpl<V extends DxDocumentVO> extends DocumentSe
result.put("DxDocument", docPage); result.put("DxDocument", docPage);
return result; return result;
} }
@SneakyThrows
@Override
public DxDocumentVO generateCatalog(Long docId) {
SearchQueryCondition queryCondition = SearchUtil.buildQueryWithOpenAttr("id", SearchItem.Operator.EQ, docId, "targetExtAtlasDrawingLink.target");
DxPageImpl<V> recursion = this.findRecursion(queryCondition);
DxDocumentVO dxDocumentVO = recursion.getContent().get(0);
List<ExtAtlasDrawingLinkVO> targetExtAtlasDrawingLink = dxDocumentVO.getDxDocumentExpand().getTargetExtAtlasDrawingLink();
if (CollectionUtil.isNotEmpty(targetExtAtlasDrawingLink)) {
List<ExtCatalogExcelVO> excelVOS = new ArrayList<>();
for (int i = 0; i < targetExtAtlasDrawingLink.size(); i++) {
DxDocumentVO documentVO = targetExtAtlasDrawingLink.get(i).getTarget();
ExtCatalogExcelVO catalogExcelVO = new ExtCatalogExcelVO();
catalogExcelVO.setIndex(String.valueOf(i + 1));
catalogExcelVO.setName(documentVO.getName());
catalogExcelVO.setVersionKey(documentVO.getVersionKey());
catalogExcelVO.setDrawNumber(String.valueOf(documentVO.getDynamicAttrs().get("drawNumber")));
catalogExcelVO.setPictureFrame(String.valueOf(documentVO.getDynamicAttrs().get("pictureFrame")));
excelVOS.add(catalogExcelVO);
}
String dir = ResourceHelper.createTemDir().getPath();
String filePath = dir + "\\图册.xlsx";
EasyExcel.write(filePath, ExtCatalogExcelVO.class)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.sheet("图册").doWrite(excelVOS);
//转pdf
String pdfName = "图册.pdf";
String filePdfPath = dir + File.separator + pdfName;
ExcelUtils.Ex2PDF(filePath, filePdfPath);
//上传文件到文件服务器
MultipartFile multipartFile = null;
multipartFile = new MockMultipartFile("file", pdfName, Constants.CONTENT_TYPE_PDF, new FileInputStream(filePdfPath));
RepoFileVO fileVO = fileManagerFeignService.uploadFile(multipartFile, CommonUtil.getBucketIdByAppName(com.yonde.dcs.document.core.constants.Constants.APPLICATION_DOC_INNER_NAME));
ObjFileLinkUtil.addFile(dxDocumentVO, fileVO, Constants.ATTACH_FILE);
dxDocumentVO.setOperator(OperatorType.MODIFY);
dxDocumentVO = this.saveRecursion((V) dxDocumentVO);
FileUtil.del(dir);
}
return dxDocumentVO;
}
} }
package com.yonde.dcs.document.core.util; package com.yonde.dcs.document.core.util;
import com.yonde.dcs.plan.common.constants.Constants;
import com.yonde.dex.dao.service.util.ApplicationContextUtil; import com.yonde.dex.dao.service.util.ApplicationContextUtil;
import com.yonde.dex.dict.feign.DictDataFeignService; import com.yonde.dex.dict.feign.DictDataFeignService;
import com.yonde.dex.dict.service.vo.DictDataVO; import com.yonde.dex.dict.service.vo.DictDataVO;
import com.yonde.dex.feign.info.DxApplicationFeignService;
import com.yonde.dex.vo.info.DxApplicationVO;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.springframework.util.ObjectUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
...@@ -14,6 +18,21 @@ import java.util.stream.Collectors; ...@@ -14,6 +18,21 @@ import java.util.stream.Collectors;
public class CommonUtil { public class CommonUtil {
/**
* 根据内部app名称 获取桶id
* @param appInnerName
* @return
*/
public static Long getBucketIdByAppName(String appInnerName) {
DxApplicationFeignService feignService = ApplicationContextUtil.getBean(DxApplicationFeignService.class);
DxApplicationVO applicationVO = feignService.findApplicationByInnerName(appInnerName);
if (!ObjectUtils.isEmpty(applicationVO)) {
return Long.valueOf(applicationVO.getBucketId());
}
return null;
}
/** /**
* 获取字典中文密级 * 获取字典中文密级
......
...@@ -2,6 +2,10 @@ package com.yonde.dcs.document.core.util; ...@@ -2,6 +2,10 @@ package com.yonde.dcs.document.core.util;
import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -13,6 +17,9 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -13,6 +17,9 @@ import org.springframework.web.multipart.MultipartFile;
*/ */
@Slf4j @Slf4j
public class ExcelUtils { public class ExcelUtils {
private static final int xlTypePDF = 0;
/** /**
* 通过名称读取Excel * 通过名称读取Excel
* *
...@@ -46,4 +53,49 @@ public class ExcelUtils { ...@@ -46,4 +53,49 @@ public class ExcelUtils {
return null; return null;
} }
} }
/***
*
* Excel转化成PDF
*
* @param inputFile
* @param pdfFile
* @return
*/
public static void Ex2PDF(String inputFile, String pdfFile) {
ActiveXComponent ax = new ActiveXComponent("Excel.Application");
Dispatch excel = null;
try {
ComThread.InitSTA(true);
log.info("开始转化Excel为PDF...");
ax.setProperty("Visible", false);
// 禁用宏
ax.setProperty("AutomationSecurity", new Variant(3));
Dispatch excels = ax.getProperty("Workbooks").toDispatch();
excel = Dispatch
.invoke(excels, "Open", Dispatch.Method,
new Object[]{inputFile, new Variant(false), new Variant(false)}, new int[9])
.toDispatch();
// 转换格式
// PDF格式=0
Dispatch.invoke(excel, "ExportAsFixedFormat", Dispatch.Method, new Object[]{new Variant(0),
// 0=标准 (生成的PDF图片不会变模糊) 1=最小文件
pdfFile, new Variant(xlTypePDF)
// (生成的PDF图片糊的一塌糊涂)
}, new int[1]);
} catch (Exception e) {
log.error("========Error:Excel文件转换失败:" + e.getMessage());
} finally {
Dispatch.call(excel, "Close", new Variant(false));
log.info("关闭excel文件");
if (ax != null) {
ax.invoke("Quit", new Variant[]{});
}
ComThread.Release();
ComThread.quitMainSTA();
}
}
} }
...@@ -5,9 +5,11 @@ import com.yonde.dcs.document.common.vo.ExtAuditObjectVO; ...@@ -5,9 +5,11 @@ import com.yonde.dcs.document.common.vo.ExtAuditObjectVO;
import com.yonde.dcs.document.common.vo.ExtInterfaceVO; import com.yonde.dcs.document.common.vo.ExtInterfaceVO;
import com.yonde.dcs.document.common.entity.vo.DxDocumentVO; import com.yonde.dcs.document.common.entity.vo.DxDocumentVO;
import com.yonde.dcs.plan.common.vo.ExtPlanVO; import com.yonde.dcs.plan.common.vo.ExtPlanVO;
import com.yonde.dex.basedata.entity.api.ApiResult;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -23,6 +25,13 @@ import java.util.Map; ...@@ -23,6 +25,13 @@ import java.util.Map;
@Api(tags = "ExtAutoTask-FEIGN") @Api(tags = "ExtAutoTask-FEIGN")
@FeignClient(value = "${dcs.feign.DCS-DOC}", path = "/task") @FeignClient(value = "${dcs.feign.DCS-DOC}", path = "/task")
public interface ExtAutoTaskServiceFeign{ public interface ExtAutoTaskServiceFeign{
@ApiOperation("生成图册目录")
@GetMapping({"/catalog"})
ApiResult generateCatalog(@RequestParam(name = "docId") Long docId);
@ApiOperation(value = "客户化文档修改状态", notes = "客户化文档修改状态", httpMethod = "POST") @ApiOperation(value = "客户化文档修改状态", notes = "客户化文档修改状态", httpMethod = "POST")
@PostMapping(value = "/extChangeDocState") @PostMapping(value = "/extChangeDocState")
void extChangeDocState(@RequestBody DxDocumentVO documentVO, @RequestParam(name = "state") String state); void extChangeDocState(@RequestBody DxDocumentVO documentVO, @RequestParam(name = "state") String state);
......
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