制度代码提交

This commit is contained in:
zhal 2023-08-01 18:59:57 +08:00
parent b002f69150
commit a97f72899e
3 changed files with 367 additions and 28 deletions

View File

@ -46,6 +46,7 @@ import org.apache.commons.compress.utils.IOUtils;
import java.awt.*;
import java.io.*;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
@ -79,7 +80,6 @@ public class InstitutionalTextWeb extends ActionWeb {
public String systemManualTextExport() {
List<String> listIds = OutputAppManager.getProfileName("");
//查询制度流程文件
List<RowMap> policyMap = DBSql.getMaps("SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLMETHODID='control.policy' ");
@ -166,7 +166,7 @@ public class InstitutionalTextWeb extends ActionWeb {
RowMap policyMap = DBSql.getMap("SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLMETHODID='control.policy' AND ID='" + targetFileIdArray[i] + "' ");
if (policyMap != null) {
exportText(policyMap.getString("ID"), policyMap.getString("WSID"), policyMap.getString("PLNAME"), policyMap.getString("PLVER"), zipName, times, targetDir, targetFileDir);
exportOnceText(policyMap.getString("ID"), policyMap.getString("WSID"), policyMap.getString("PLNAME"), policyMap.getString("PLVER"), zipName, times, targetDir, targetFileDir);
}
}
@ -184,6 +184,7 @@ public class InstitutionalTextWeb extends ActionWeb {
}
@SuppressWarnings("deprecation")
public void exportText(String targetFileId, String wsId, String plname, String versionNumer, String zipName, long times, String targetDir, File targetFileDir) {
ProcessInstance boProcessInstance = SDK.getProcessAPI()
@ -300,14 +301,9 @@ public class InstitutionalTextWeb extends ActionWeb {
msg = sourceDc.getDCMessage().getMessage();
}
}
try {
IOUtils.copy(in, out);
in.close();
out.close();
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
IOUtils.copy(in, out);
in.close();
out.close();
if (filePath != null) {
@ -355,6 +351,138 @@ public class InstitutionalTextWeb extends ActionWeb {
}
public void exportOnceText(String targetFileId, String wsId, String plname, String versionNumer, String zipName, long times, String targetDir, File targetFileDir) {
ProcessInstance boProcessInstance = SDK.getProcessAPI()
.createBOProcessInstance("obj_c0fd5262f1c64df9ab5e725aae3eff2e", "admin", "正文导出");
String fileName = null;
try {
String tempName = "制度-手册7.xml";
String tempPath = "../apps/install/com.awspaas.user.apps.coe.pal.output.zd/";
String fileValue = UUIDGener.getUUID() + "_outputText";
String sourceAppId = "com.awspaas.user.apps.coe.pal.output.zd";
String filename = plname;
DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, filename);
String docPath = sourceDc.getPath();
UtilFile upfileDir = new UtilFile(docPath);
if (!upfileDir.exists()) {
upfileDir.mkdirs();
}
//{"orderNuberFirst":true,"targetShape":"","targetFileId":"ca45dc6a-0f77-44ee-adfe-f36b014586f3",
// "orderNametwo":false,"reportNameIsItName":"%fileName%_%fileVersion%","relationFileId":"","isItReport":true}
JSONObject wizardJsonData = new JSONObject();
wizardJsonData.put("orderNuberFirst", true);
wizardJsonData.put("targetShape", "");
wizardJsonData.put("targetFileId", targetFileId);
wizardJsonData.put("orderNametwo", false);
wizardJsonData.put("reportNameIsItName", "%fileName%_%fileVersion%");
wizardJsonData.put("relationFileId", "");
wizardJsonData.put("isItReport", true);
String reportName = wizardJsonData.getString("reportNameIsItName"); //页面上设计的文件命名规则
Map<String, Integer> indexMap = new HashMap<String, Integer>();
PALRepositoryModel model = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(targetFileId);
if (model != null) {
//获取文件扩展属性
String json = CoePropertyUtil.getPropertyValue(model.getId() + "_attr");
JSONObject extendAttr = new JSONObject();
if (json != null && !"".equals(json) && !"null".equals(json)) {
JSONArray jsonArray = JSONArray.parseArray(json);
for (int j = 0; j < jsonArray.size(); j++) {
JSONObject object = jsonArray.getJSONObject(j);
extendAttr.put(object.getString("id"), object.get("value"));
}
}
//文件的扩展属性
List<PALRepositoryPropertyModel> repositoryPropertyList = PALRepositoryPropertyCache.getPropertyByPlId(model.getId());
if (repositoryPropertyList != null && repositoryPropertyList.size() > 0) {
for (PALRepositoryPropertyModel repositoryPropertyModel : repositoryPropertyList) {
if ("P_versions".equals(repositoryPropertyModel.getPropertyId())) {
String plvers = model.getVersion() + "";
String plver = "";
if (!"".equals(plvers)) {
if (plvers.length() > 1) {
plver = plvers.substring(0, 1) + "."
+ plvers.substring(plvers.length() - 1, plvers.length());
} else {
plver = plvers.substring(0, 1) + ".0";
}
}
extendAttr.put(repositoryPropertyModel.getPropertyId(), "V" + plver);
} else {
extendAttr.put(repositoryPropertyModel.getPropertyId(), repositoryPropertyModel.getPropertyValue());
}
}
}
List<String> reportNameLabels = OutputExcelUtil.string2label(reportName);
String reportNameValue = reportName;
if (reportNameLabels.size() > 0) {
reportNameValue = OutputExcelUtil.label2value(model, extendAttr, null, reportName);
}
reportNameValue = reportNameValue.replaceAll(OutputExcelUtil.FILENAMEREGX, "");
if (reportNameValue.length() > 255) {
reportNameValue = reportNameValue.substring(0, 255);
}
String docName = "";
if (indexMap.containsKey(reportNameValue)) {
int index = indexMap.get(reportNameValue);
index++;
fileName = reportNameValue + "(" + index + ")";
log.info("得到word名称为:" + fileName);
docName = docPath + fileName + ".doc";
indexMap.put(reportNameValue, index);
} else {
fileName = reportNameValue;
log.info("得到word名称为:" + fileName);
docName = docPath + fileName + ".doc";
indexMap.put(fileName, 1);
}
JSONObject dataMap = getData2(targetFileId, wizardJsonData, docPath, fileName);
System.out.println("dpcpath=======" + docPath);
if (dataMap != null) {
String filePath = createDoc2(dataMap, tempPath, tempName, docName, wizardJsonData, targetFileId, docPath);
DCContext sourceDc2 = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, fileName + ".doc");
String downUrl = SDK.getConfAPI().getPortalUrl() + "/r/"
+ sourceDc2.getDownloadURL().replace("./", "");
File targetFile = new File(targetDir + fileName + ".doc");
if (!targetFile.exists()) {
targetFile.createNewFile();
}
OutputStream out = new FileOutputStream(targetFile);
InputStream in = DCUtil.decryptFile(sourceDc2);
if (in == null) {
String msg = "+ dcContext.getFileName() + ";
if (sourceDc.getDCMessage() != null) {
msg = sourceDc.getDCMessage().getMessage();
}
}
IOUtils.copy(in, out);
in.close();
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成word文件
*
@ -448,6 +576,7 @@ public class InstitutionalTextWeb extends ActionWeb {
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
System.out.println("文件名称为================" + fileName);
if (suffix.equals("xml")) {
// 输出文档路径及名称
File sourceFile = new UtilFile(path + fileName);
@ -571,8 +700,7 @@ public class InstitutionalTextWeb extends ActionWeb {
TableRow row = table.getRows().get(0);
row.isHeader(true);
row.setHeight(20);
row.setHeightType(TableRowHeightType.Exactly);
row.setHeightType(TableRowHeightType.Auto);
//循环表头
for (int i = 0; i < header.length; i++) {
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
@ -627,8 +755,10 @@ public class InstitutionalTextWeb extends ActionWeb {
JSONArray organizationTable = new JSONArray(); //组织职责Table
// 属性特征 属性代码KEY
PALRepositoryPropertyModel Organizational = PALRepositoryPropertyCache.getPropertyByPropertyId(repositoryModel.getId(), "Organizational_role");
String OrganizationalVal = Organizational.getPropertyValue();
JSONObject OrganizationalObj = JSONObject.parseObject(OrganizationalVal);
if (OrganizationalObj != null && !OrganizationalObj.isEmpty()) {
JSONArray tableArr = OrganizationalObj.getJSONArray("table");
@ -674,7 +804,7 @@ public class InstitutionalTextWeb extends ActionWeb {
TableRow row = table.getRows().get(0);
row.isHeader(true);
row.setHeight(20);
row.setHeightType(TableRowHeightType.Exactly);
row.setHeightType(TableRowHeightType.Auto);
for (int i = 0; i < orgheader.length; i++) {
row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
//设置固定列宽
@ -743,7 +873,7 @@ public class InstitutionalTextWeb extends ActionWeb {
com.sini.com.spire.doc.Document document2 = new com.sini.com.spire.doc.Document(appendUrl);
int sectionCount = document.getSections().getCount();
int sectionCount = document2.getSections().getCount();
ProcessInstance boProcessInstance = SDK.getProcessAPI()
.createBOProcessInstance("obj_70c7c5eb0e8f425fa1b57a94038089a8", "admin", "页面方向");
@ -751,7 +881,7 @@ public class InstitutionalTextWeb extends ActionWeb {
boolean isLandscape = false;
// 循环遍历每个节Section
for (int i = 0; i < sectionCount; i++) {
Section souresection = document.getSections().get(i);
Section souresection = document2.getSections().get(i);
// 获取当前节的页面方向
PageSetup pageSetup = souresection.getPageSetup();
@ -777,11 +907,11 @@ public class InstitutionalTextWeb extends ActionWeb {
//保存结果文档
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
BO bo = new BO();
/*BO bo = new BO();
bo.set("FILENAME", fileName);
bo.set("PALID", repositoryId);
bo.set("PAGE_ORIENTATION", "横向");
SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), "");
SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), "");*/
} else {
@ -804,11 +934,11 @@ public class InstitutionalTextWeb extends ActionWeb {
//保存结果文档
document.saveToFile(outFile.getPath(), FileFormat.Docx_2013);
BO bo = new BO();
/*BO bo = new BO();
bo.set("FILENAME", fileName);
bo.set("PALID", repositoryId);
bo.set("PAGE_ORIENTATION", "纵向");
SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), "");
SDK.getBOAPI().create("BO_ACT_PAGE_ORIENTATION", bo, boProcessInstance.getId(), "");*/
}
}
@ -822,9 +952,6 @@ public class InstitutionalTextWeb extends ActionWeb {
//创建 Document 类的对象并从磁盘加载 Word 文档
com.sini.com.spire.doc.Document document = new com.sini.com.spire.doc.Document(outFile.getPath());
// 删除第一页
/*Section section1 = document.getSections().get(0);
document.getSections().remove(section1);*/
Section section = document.getLastSection();
@ -884,10 +1011,6 @@ public class InstitutionalTextWeb extends ActionWeb {
com.sini.com.spire.doc.Document doc3 = new com.sini.com.spire.doc.Document();
doc3.loadFromFile(tempPath + "横板页眉页脚模板.doc");
// 获取源文档的页眉页脚
/*Section sourceSection = doc1.getSections().get(0);
HeaderFooter sourceHeader = sourceSection.getHeadersFooters().getHeader();
HeaderFooter sourceFooter = sourceSection.getHeadersFooters().getFooter();*/
// 将页眉复制到目标文档的第一节以及后续节
for (int i = 0; i < doc2.getSections().getCount(); i++) {
@ -1005,4 +1128,201 @@ public class InstitutionalTextWeb extends ActionWeb {
}
public String systemManualTextTextOriginal() {
List<String> listIds = OutputAppManager.getProfileName("");
//查询制度流程文件
List<RowMap> policyMap = DBSql.getMaps("SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLMETHODID='control.policy' ");
String downUrl = "";
Date date = new Date();
SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyyMMddhhmmss");
long times = System.currentTimeMillis();
final String zipName = "批量下载正文原文导出" + dateFormat.format(date) + ".zip";
String targetDir = AWSServerConf.getProperty("dc.path") + File.separator + "com.awspaas.user.apps.coe.pal.output.zd" + File.separator + "tmp/grouppackage/zip" + times + "/";
File targetFileDir = new File(targetDir);
if (!targetFileDir.exists()) {
targetFileDir.mkdirs();
}
for (int i = 0; i < policyMap.size(); i++) {
vvvv(policyMap.get(i).getString("ID"), policyMap.get(i).getString("WSID"), policyMap.get(i).getString("PLNAME"), policyMap.get(i).getString("PLVER"), zipName, times, targetDir, targetFileDir);
}
try {
UtilFile.zipCompress(targetDir, new File(targetDir + zipName));
File[] files = targetFileDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.equals(zipName)) {
return false;
}
return true;
}
});
} catch (Exception e) {
e.printStackTrace();
}
DCContext zipDcContext = new DCContext(getContext(), DCProfileManager.getDCProfile("com.awspaas.user.apps.coe.pal.output.zd", "tmp"), "com.awspaas.user.apps.coe.pal.output.zd", "grouppackage", "zip" + times, zipName);
downUrl = SDK.getConfAPI().getPortalUrl() + "/r/" + zipDcContext.getDownloadURL().replace("./", "");
return downUrl;
}
public void vvvv(String targetFileId, String wsId, String plname, String versionNumer, String zipName, long times, String targetDir, File targetFileDir) {
ProcessInstance boProcessInstance = SDK.getProcessAPI()
.createBOProcessInstance("obj_ddbc1403613b42279439eb35069be0f0", "admin", "正文原文导出");
PALRepositoryModel model = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(targetFileId);
String fileName = null;
try {
String tempName = "制度-手册7.xml";
String tempPath = "../apps/install/com.awspaas.user.apps.coe.pal.output.zd/";
String fileValue = UUIDGener.getUUID() + "_outputText";
String sourceAppId = "com.awspaas.user.apps.coe.pal.output.zd";
String filename = plname;
DCContext sourceDc = new DCContext(_uc, DCProfileManager.getDCProfile(sourceAppId, "output"), sourceAppId, wsId, fileValue, filename);
String docPath = sourceDc.getPath();
UtilFile upfileDir = new UtilFile(docPath);
if (!upfileDir.exists()) {
upfileDir.mkdirs();
}
//{"orderNuberFirst":true,"targetShape":"","targetFileId":"ca45dc6a-0f77-44ee-adfe-f36b014586f3",
// "orderNametwo":false,"reportNameIsItName":"%fileName%_%fileVersion%","relationFileId":"","isItReport":true}
JSONObject wizardJsonData = new JSONObject();
wizardJsonData.put("orderNuberFirst", true);
wizardJsonData.put("targetShape", "");
wizardJsonData.put("targetFileId", targetFileId);
wizardJsonData.put("orderNametwo", false);
wizardJsonData.put("reportNameIsItName", "%fileName%_%fileVersion%");
wizardJsonData.put("relationFileId", "");
wizardJsonData.put("isItReport", true);
String reportName = wizardJsonData.getString("reportNameIsItName"); //页面上设计的文件命名规则
Map<String, Integer> indexMap = new HashMap<String, Integer>();
if (model != null) {
String filePath1 = upfileText(targetFileId);
if (filePath1 != null) {
File oldpaths = new File(filePath1);
File newpaths = new File(targetDir + filePath1.substring(filePath1.lastIndexOf("/") + 1));
if (!newpaths.exists()) {
Files.copy(oldpaths.toPath(), newpaths.toPath());
} else {
newpaths.delete();
Files.copy(oldpaths.toPath(), newpaths.toPath());
}
BO bo = new BO();
bo.set("PALID", targetFileId);
bo.set("FILENAME", filePath1.substring(filePath1.lastIndexOf("/") + 1));
bo.set("VERSIONNUMBER", versionNumer);
bo.set("UPFILESTATE", "下载成功");
bo.set("PALNAME", model.getName());
SDK.getBOAPI().create("BO_ACT_TEXT_ORIGIN_EXPORT", bo, boProcessInstance.getId(), "");
}
}
} catch (Exception e) {
e.printStackTrace();
BO bo = new BO();
bo.set("PALID", targetFileId);
bo.set("FILENAME", model.getName());
bo.set("VERSIONNUMBER", versionNumer);
bo.set("UPFILESTATE", "下载失败");
bo.set("PALNAME", model.getName());
bo.set("REASONSPROBLEM", e.getMessage());
SDK.getBOAPI().create("BO_ACT_TEXT_DERIVATION", bo, boProcessInstance.getId(), "");
}
}
public String upfileText(String repositoryId) {
//***********************************************************使用spire 生成模板后复制文件****************************************************/
List<Map<String, Object>> repositoryFileElements = CoeDesignerUtil.getShapeMessageJson4(repositoryId); //流程文件内容
String controlShapeId = "";
if (repositoryFileElements != null) {
int index = 1;// 流程步骤序号
int dangerIndex = 1;// 风险序号
int regulateIndex = 1;// 控制序号
for (Map<String, Object> shape : repositoryFileElements) {
String type = shape.get("type").toString();
if ("regulation".equals(type)) {
controlShapeId = shape.get("id").toString();
} else if ("I/O_L4".equals(type)) {
controlShapeId = shape.get("id").toString();
}
}
}
UserContext userContext = DispatcherRequest.getUserContext();
Map<String, String> result = new HashMap<>();
result.put("listDef", "");
result.put("content", "");
if (UtilString.isEmpty(controlShapeId)) {
}
PALRepositoryModel repositoryModel = PALRepositoryQueryAPIManager.getInstance().queryPalRepositoryModelByPalId(repositoryId);
if (repositoryModel == null) {
}
String content = "";
StringBuilder listStr = new StringBuilder();
// 读取附件
// 流程附件列表
UpFileDao upFileDao = new UpFileDao();
List<UpfileModel> search = upFileDao.search(repositoryModel.getId(), controlShapeId, null);
DCContext dcContextpdf = null;
File file = null;
String fileUrl = null;
if (search != null && search.size() > 0) {
long b1 = System.currentTimeMillis();
// 复制附件
for (UpfileModel upfileModel : search) {
DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE);
if (dcProfile != null) {
dcContextpdf = new DCContext(userContext, dcProfile, CoEConstant.APP_ID, upfileModel.getPl_uuid(), upfileModel.getShape_uuid(), upfileModel.getFileName());
String path = dcContextpdf.getPath();
String fileName = dcContextpdf.getFileName();
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
fileUrl = path + fileName;
}
}
}
return fileUrl;
}
}

View File

@ -204,4 +204,23 @@ public class ReportPrController {
}
/**
* 制度手册正文导出
*
* @param me
* @param teamId
* @param wsid
* @return
*/
@Mapping("com.awspaas.user.apps.coe.pal.output.zd_systemManualTextTextOriginal")
public String systemManualTextTextOriginal(UserContext me) {
ResponseObject ro = null;
ro = ResponseObject.newOkResponse();
InstitutionalTextWeb institutionalTextWeb = new InstitutionalTextWeb(me);
String result = institutionalTextWeb.systemManualTextTextOriginal();
ro.put("result", result);
return ro.toString();
}
}

View File

@ -4397,7 +4397,7 @@ y7fdOgAAAABJRU5ErkJggk==
</w:rPr>
</w:pPr>
</w:p>-->
<w:p wsp:rsidR="002737AF" wsp:rsidRDefault="002737AF" wsp:rsidP="00E1269B">
<!--<w:p wsp:rsidR="002737AF" wsp:rsidRDefault="002737AF" wsp:rsidP="00E1269B">
<w:pPr>
<w:spacing w:line="360" w:line-rule="auto"/>
<w:rPr>
@ -5170,7 +5170,7 @@ y7fdOgAAAABJRU5ErkJggk==
</w:tc>
</w:tr>
</#list>
</w:tbl>
</w:tbl>-->
<!-- <w:p wsp:rsidR="002737AF" wsp:rsidRDefault="002737AF" wsp:rsidP="00F96B41">
<w:pPr>
<w:rPr>