diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2Gener.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2Gener.java index 85004cd3..87f5d977 100644 --- a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2Gener.java +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2Gener.java @@ -1,13 +1,7 @@ package com.actionsoft.apps.coe.pal.output.or.report2; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.io.*; +import java.util.*; import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache; import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; @@ -18,11 +12,17 @@ import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppProfile; import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel; import com.actionsoft.apps.coe.pal.pal.output.util.OutputExcelUtil; import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache; import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.dao.DesignerShapeRelationDao; import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.DesignerShapeRelationModel; import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.util.DBSql; +import com.actionsoft.bpms.util.UtilFile; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -33,6 +33,15 @@ import com.actionsoft.bpms.server.fs.DCContext; import com.actionsoft.bpms.util.UtilString; import com.actionsoft.sdk.local.SDK; import com.actionsoft.sdk.local.api.internal.PlatformAPIImpl; +import com.awspaas.user.apps.yili.reportform.util.RepositoryAttribute; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import org.springframework.util.StringUtils; + +import static com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil.getLastPublishTaskIdByModelId; +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toCollection; /** * 生成岗位手册-横表的入口 @@ -65,6 +74,7 @@ public class Report2Gener { isRunning = true; String teamId = model.getTeamId(); String wsId = model.getWsId(); + String userId = model.getUserId(); log.info("execute ready..."); log.info("-------------------"); log.info("TeamId=" + teamId); @@ -82,9 +92,9 @@ public class Report2Gener { if (!UtilString.isEmpty(targetFileIds)) { if (isJsonArray(targetFileIds)) { JSONArray array = JSONArray.parseArray(targetFileIds); - genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj, array); + genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj, array,userId); } else { - genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj); + genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj,userId); } } log.info("end"); @@ -104,7 +114,7 @@ public class Report2Gener { } } - private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData) { + private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData,String userId) { String[] targetShapes = wizardJsonData.getString("targetShape").split(","); String[] repositoryIds = wizardJsonData.getString("targetFileId").split(","); String repositoryId = null; @@ -154,24 +164,41 @@ public class Report2Gener { indexMap.put(shapeName, index); } else { log.info("得到word名称为:" + shapeName); - docName = docPath + shapeName + ".doc"; + docName = docPath + UserContext.fromUID(userId).getUserModel().getPositionName() + ".doc"; indexMap.put(shapeName, 1); } - - JSONObject dataMap = getData(targetShapeId, shapesMap, linkerList, wizardJsonData); - OutputWordUtil.createDoc(dataMap, tempPath, tempName, docName); + + + /*List lists = new LinkedList<>(); + List nodeRowMaps = DBSql.getMaps( + "SELECT NODEID,NODENAME,ITSYSVAL,NODETYPE,PLID,PLNAME,ACTIVITYNUMBER,ACTIVITYDESC,ROLE,ROLENAME,POST,POSTNAME FROM BO_EU_PAL_FILENODE6 WHERE POST LIKE '%" + + UserContext.fromUID(userId).getUserModel().getPositionName()+ "%' OR POST LIKE '%内蒙古伊利实业集团股份有限公司%'"); + for (RowMap rowMap: + nodeRowMaps) { + String plid = rowMap.getString("PLID"); + if (!lists.contains(plid)){ + lists.add(plid); + } + } + System.out.println("size>>>>>>>>"+lists.size());*/ + + JSONArray jsonArray = getData(targetShapeId, shapesMap, linkerList, wizardJsonData,userId); + for (int i=0;i> shapesMap, - List> linkerList, JSONObject wizardJsonData) { - - JSONObject dataMap = new JSONObject(); - - OrReportComment orReportComment = new OrReportComment(); - orReportComment.getCommentContent(dataMap, shapesMap, shapeId); //获取一些公共的数据(手册首页的手册岗位名称、部门、公司、时间、岗位职责等) + + + private JSONArray getData(String shapeId, Map> shapesMap, + List> linkerList, JSONObject wizardJsonData,String userId) { + JSONArray jsonArray = new JSONArray(new LinkedList<>()); + //流程表格 + JSONArray positionTable = new JSONArray(); //相关流程 JSONArray repositoryTable = new JSONArray(); //相关流程 JSONArray repositoryShapeTable = new JSONArray(); //流程步骤 JSONArray institutionTable = new JSONArray(); //相关制度 @@ -185,101 +212,169 @@ public class Report2Gener { Set formSet = new HashSet(); Set itsystemSet = new HashSet(); Set KPISet = new HashSet(); - - String[] relationFileIds = wizardJsonData.getString("relationFileId").split(","); //页面选择的关联文件Id数组 - DesignerShapeRelationDao dao = new DesignerShapeRelationDao(); - - // 记录查询过的文件,避免重复查询 - Map> map = new HashMap<>();// key: fileId value: shapes - - int index = 1; - for (String relationFileId : relationFileIds) { - if (relationFileId.equals("")) { - continue; + //updateOtherTableInfo(dataMap,repositoryShapeTable, institutionTable, formTable, itsystemTable, KPITable); + List lists = new LinkedList<>(); + List nodeRowMaps = DBSql.getMaps( + "SELECT NODEID,NODENAME,ITSYSVAL,NODETYPE,PLID,PLNAME,ACTIVITYNUMBER,ACTIVITYDESC,ROLE,ROLENAME,POST,POSTNAME FROM BO_EU_PAL_FILENODE6 WHERE POST LIKE '%" + + UserContext.fromUID(userId).getUserModel().getPositionName()+ "%' OR POST LIKE '%内蒙古伊利实业集团股份有限公司%'"); + for (RowMap rowMap: + nodeRowMaps) { + String plid = rowMap.getString("PLID"); + if (!lists.contains(plid)){ + lists.add(plid); } - - List relationModelList = dao.getModelListByRelationShapeId(relationFileId, shapeId); // 关联信息 - if (relationModelList != null && relationModelList.size() > 0) { - PALRepositoryModel relationModel = (PALRepositoryModel) CoeProcessLevelDaoFacotory.createCoeProcessLevel().getInstance(relationFileId); - List> relationFileElements = CoeDesignerUtil.getShapeMessageJson4(relationFileId); // 关联流程文件内容 - if (wizardJsonData.getBoolean("orderNuberFirst")) { - OutputWordUtil.orderByNumber(relationFileElements); - } - Set shapeIds = new HashSet<>(); - for (DesignerShapeRelationModel srModel : relationModelList) { - if (UtilString.isEmpty(srModel.getShapeId())) { - continue; - } - shapeIds.add(srModel.getShapeId()); + } + System.out.println("size>>>>>>>>"+lists.size()); + + for (int q =0;q< lists.size();q++){ + JSONObject dataMap = new JSONObject(); + OrReportComment orReportComment = new OrReportComment(); + orReportComment.getCommentContent(dataMap, shapesMap, shapeId,userId); //获取一些公共的数据(手册首页的手册岗位名称、部门、公司、时间、岗位职责等) + + System.out.println("循环了几次>>>>>>>" + q); + //这个代码是为了解决 岗位参与执行的流程存储 + JSONObject _tr = new JSONObject(new LinkedHashMap<>()); + _tr.put("nums", q + 1); + positionTable.add(_tr); + //dataMap.put("position_table", positionTable); + + //这块代码主要是为了存储流程名称 + PALRepositoryModel palRepositoryModel = PALRepositoryCache.getCache().get(lists.get(q)); + String name = palRepositoryModel.getName(); + JSONObject _tr_prcoess = new JSONObject(new LinkedHashMap<>()); + _tr.put("numbers", 1); + _tr.put("shape_name", name); + dataMap.put("position_table", positionTable); + + List nodeRowMaps_shape = DBSql.getMaps( + "SELECT * FROM (SELECT NODEID,NODENAME,ITSYSVAL,NODETYPE,PLID,PLNAME,ACTIVITYNUMBER,ACTIVITYDESC,ROLE,ROLENAME,POST,POSTNAME FROM BO_EU_PAL_FILENODE6 WHERE POST LIKE '%" + + UserContext.fromUID(userId).getUserModel().getPositionName() + "%' OR POST LIKE '%内蒙古伊利实业集团股份有限公司%') WHERE PLID = '" + lists.get(q) + "'"); + int m = 1; + System.out.println("nodeRowMaps_shape>>>>>>>>>" + nodeRowMaps_shape.size()); + for (RowMap rowMap : + nodeRowMaps_shape) { + JSONObject _tr_shape = new JSONObject(new LinkedHashMap<>()); + String activitydesc = rowMap.getString("ACTIVITYDESC"); + String nodename = rowMap.getString("NODENAME"); + _tr_shape.put("numbers", m); + _tr_shape.put("shape_name", nodename); + _tr_shape.put("shape_desc", activitydesc); + String nodetype = rowMap.getString("NODETYPE"); + if (nodetype.equals("method_approval_node")) { + _tr_shape.put("shape_type", "审批类(线上审批)"); + } else if (nodetype.equals("method_service_node")) { + _tr_shape.put("shape_type", "审批类(线下审批)"); + } else if (nodetype.equals("method_approval_node3")) { + _tr_shape.put("shape_type", "操作类(系统活动)"); + } else if (nodetype.equals("method_service_node4")) { + _tr_shape.put("shape_type", "操作类(人工活动)"); } + String rolename = rowMap.getString("ROLENAME"); + _tr_shape.put("shape_role", rolename); + m++; + repositoryShapeTable.add(_tr_shape); + } + dataMap.put("repository_table", repositoryShapeTable); - for (Map shapeMap : relationFileElements) { - String id = shapeMap.get("id").toString(); - if (!shapeIds.contains(id)) { - continue; - } - JSONObject _tr = new JSONObject(); - OutputWordUtil.setShapeDefaultValue2(relationFileId, _tr); - _tr.put(OutputWordUtil.SERIAL_NUMBER, index); //序号 - _tr.put(OutputWordUtil.REPOSITORY_NAME, relationModel.getName().toString().replace("\n", "")); //流程名称 - _tr.put(OutputWordUtil.SHAPE_ID, shapeMap.get("id")); //步骤元素id - _tr.put(OutputWordUtil.SHAPE_NAME, shapeMap.get("text").toString().replace("\n", OutputWordUtil.WRAPSTRING)); //步骤名称 + //这里是对流程制度/表单/模版进行存储数据 + Map queryRepositoryAttributeById = new RepositoryAttribute().queryRepositoryAttributeById(lists.get(q)); + if (null != queryRepositoryAttributeById && !queryRepositoryAttributeById.isEmpty()) { - JSONArray dataAttributes = (JSONArray) shapeMap.get("attributes"); - if (!dataAttributes.isEmpty()) { - for (int i = 0; i < dataAttributes.size(); i++) { - JSONObject obj = dataAttributes.getJSONObject(i); - String attrId = obj.getString("key"); - String attrValue = obj.getString("value"); - _tr.put("shape_" + attrId, attrValue.replace("\n", OutputWordUtil.WRAPSTRING)); + //这块是取适用范围的字段数据 + String applicant = ""; + JSONObject application = queryRepositoryAttributeById.get("application"); + if (null != application && !application.equals("")) { + JSONArray PUBDEPTJA = application.getJSONArray("value"); + if (null != PUBDEPTJA && !PUBDEPTJA.isEmpty()) { + for (Object PUBDEPTO : PUBDEPTJA) { + JSONObject _tr_institutionTable = new JSONObject(new LinkedHashMap<>()); + JSONObject PUBDEPTJO = JSONObject.parseObject(String.valueOf(PUBDEPTO)); + String dempId = PUBDEPTJO.getString("id"); + applicant += dempId; } } - repositoryShapeTable.add(_tr); - if (!repositoryNameList.contains(relationModel.getName())) { - repositoryNameList.add(relationModel.getName()); + } + // 获取相关文件 + + + List relationList2 = DesignerShapeRelationCache.getListByAttrId(lists.get(q), "", "R_relevant_flies"); + int o = 1; + System.out.println("shuj>>>>>>>>" + relationList2.size()); + if (relationList2.size() > 0) { + for (DesignerShapeRelationModel relation : relationList2) { + String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID + PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId); + if (model != null) { + JSONObject _tr_institutionTable = new JSONObject(new LinkedHashMap<>()); + String names = model.getName(); + if (!names.isEmpty()) { + _tr_institutionTable.put("numbers", o); + _tr_institutionTable.put("institution_name", names); + PALRepositoryModel dempId_pal_model = PALRepositoryCache.getCache().get(model.getId()); + _tr_institutionTable.put("version", dempId_pal_model.getVersion()); + _tr_institutionTable.put("application", applicant); + institutionTable.add(_tr_institutionTable); + o++; + } + } } - if (!map.containsKey(relationModel.getId())) { - map.put(relationModel.getId(), new ArrayList()); - } - map.get(relationModel.getId()).add(id); - index++; + } + dataMap.put("institution_tables", institutionTable); + } + + + //这个是存储相关IT系统数据 + List list_it_system = new LinkedList<>(); + for (RowMap rowMap : + nodeRowMaps_shape) { + String itsysval = rowMap.getString("ITSYSVAL"); + if (!list_it_system.contains(itsysval)) { + list_it_system.add(itsysval); } } - } - - //相关流程Table - int i = 1; - for (String it : repositoryNameList) { - JSONObject _tr = new JSONObject(); - _tr.put(OutputWordUtil.SERIAL_NUMBER, i); - _tr.put(OutputWordUtil.REPOSITORY_NAME, it.replace("\n", "")); - repositoryTable.add(_tr); - i++; - } - Map>> recordsMap = new HashMap<>(); - // 制度、表单、IT系统、绩效考核数据 - for (Map.Entry> entry : map.entrySet()) { - String fileId = entry.getKey(); - for (String id : entry.getValue()) { - // 制度 - getRelationData(institutionTable, "institution", fileId, id, institutionSet, dao, recordsMap); - // 表单 - getRelationData(formTable, "form", fileId, id, formSet, dao, recordsMap); - // it系统 - getRelationData(itsystemTable, "itsystem", fileId, id, itsystemSet, dao, recordsMap); - // kpi绩效 - getRelationData(KPITable, "kpi", fileId, id, KPISet, dao, recordsMap); + int t = 1; + for (int r = 0; r < list_it_system.size(); r++) { + if (StringUtils.isEmpty(list_it_system.get(r))) { + JSONObject _tr_it_system = new JSONObject(new LinkedHashMap<>()); + _tr_it_system.put("numbers", t); + _tr_it_system.put("it_name", list_it_system.get(r)); + itsystemTable.add(_tr_it_system); + t++; + } } + dataMap.put("it_system_table", itsystemTable); + //这个是存储kpi数据 + + List relationList2 = DesignerShapeRelationCache.getListByAttrId(lists.get(q), "", "Process_performance_metrics"); + + int u = 1; + if (relationList2.size() > 0) { + for (DesignerShapeRelationModel relation : relationList2) { + String relationFileId = relation.getRelationFileId();// 支持或相关文件的ID + PALRepositoryModel model = PALRepositoryCache.getCache().get(relationFileId); + if (model != null) { + JSONObject _tr_kpi = new JSONObject(new LinkedHashMap<>()); + _tr_kpi.put("numbers", u); + String names = model.getName(); + _tr_kpi.put("kpi_name", names); + _tr_kpi.put("kpi_number", ""); + KPITable.add(_tr_kpi); + u++; + } + } + + } + dataMap.put("kpi_table", KPITable); + //这里是存储数据表格 + //for (int i=0;i<2;i++){ + System.out.println("dataMap>>>>>>>>>>>>>>>"+dataMap.toString()); + updateOtherTableInfo(dataMap, repositoryShapeTable, institutionTable, formTable, itsystemTable, KPITable); + //} + jsonArray.add(dataMap); } - - dataMap.put(OutputWordUtil.TABLE_REPOSITORY, repositoryTable); - dataMap.put(OutputWordUtil.TABLE_REPOSITORY_SHAPE, repositoryShapeTable); - // 完善部分表格信息 - updateOtherTableInfo(dataMap, institutionTable, formTable, itsystemTable, KPITable); - - return dataMap; + return jsonArray; } /** @@ -290,12 +385,14 @@ public class Report2Gener { * @param itsystemTable * @param KPITable */ - private void updateOtherTableInfo(JSONObject dataMap, JSONArray institutionTable, JSONArray formTable, JSONArray itsystemTable, JSONArray KPITable) { + private void updateOtherTableInfo(JSONObject dataMap,JSONArray repositoryShapeTable, JSONArray institutionTable, JSONArray formTable, JSONArray itsystemTable, JSONArray KPITable) { //制度 if (institutionTable.size() == 0) { institutionTable = getEmptyTable("control.policy"); } dataMap.put(OutputWordUtil.TABLE_INSTITUTION, institutionTable); + //相关职责 + dataMap.put(OutputWordUtil.TABLE_REPOSITORY, repositoryShapeTable); //表单 if (formTable.size() == 0) { formTable = getEmptyTable("data.form"); @@ -317,6 +414,10 @@ public class Report2Gener { institutionTable.getJSONObject(j).put(OutputWordUtil.SERIAL_NUMBER, j + 1); } + for (int j = 0; j < repositoryShapeTable.size(); j++) { + repositoryShapeTable.getJSONObject(j).put(OutputWordUtil.SERIAL_NUMBER, j + 1); + } + for (int j = 0; j < formTable.size(); j++) { formTable.getJSONObject(j).put(OutputWordUtil.SERIAL_NUMBER, j + 1); } @@ -395,7 +496,7 @@ public class Report2Gener { /**********************关联AWS组织的excel处理***************************/ - private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData, JSONArray targetFileIds) { + private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData, JSONArray targetFileIds,String userId) { // 按照名称排序 List roleList = new ArrayList<>(); for (int i = 0; i < targetFileIds.size(); i++) { @@ -437,17 +538,17 @@ public class Report2Gener { indexMap.put(shapeName, 1); } - JSONObject dataMap = getData(role, wizardJsonData); + JSONObject dataMap = getData(role, wizardJsonData,userId); OutputWordUtil.createDoc(dataMap, tempPath, tempName, docName); } } - private JSONObject getData(RoleModel role, JSONObject wizardJsonData) { + private JSONObject getData(RoleModel role, JSONObject wizardJsonData,String userId) { JSONObject dataMap = new JSONObject(); OrReportComment orReportComment = new OrReportComment(); - orReportComment.getAwsOrgCommentContent(dataMap, role); //获取一些公共的数据(手册首页的手册岗位名称、部门、公司、时间、岗位职责等) + orReportComment.getAwsOrgCommentContent(dataMap, role,userId); //获取一些公共的数据(手册首页的手册岗位名称、部门、公司、时间、岗位职责等) //流程表格 JSONArray repositoryTable = new JSONArray(); //相关流程 @@ -525,7 +626,14 @@ public class Report2Gener { } } } - + + + + + + + + //相关流程Table int i = 1; for (String it : repositoryNameList) { @@ -556,11 +664,16 @@ public class Report2Gener { dataMap.put(OutputWordUtil.TABLE_REPOSITORY_SHAPE, repositoryShapeTable); // 完善部分表格信息 - updateOtherTableInfo(dataMap, institutionTable, formTable, itsystemTable, KPITable); + + //for (int s=0;s<=2;s++){ + + updateOtherTableInfo(dataMap,new JSONArray(), institutionTable, formTable, itsystemTable, KPITable); + // } return dataMap; } /**********************关联AWS组织的excel处理***************************/ + }