diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/EndEvent.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/EndEvent.java new file mode 100644 index 00000000..c8da04e8 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/EndEvent.java @@ -0,0 +1,20 @@ +package com.actionsoft.apps.coe.pal.output.or; + +import com.actionsoft.apps.listener.AppListener; +import com.actionsoft.apps.resource.AppContext; + +public class EndEvent implements AppListener { + + @Override + public void after(AppContext arg0) { + // TODO Auto-generated method stub + + } + + @Override + public boolean before(AppContext arg0) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/Plugins.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/Plugins.java new file mode 100644 index 00000000..341450b8 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/Plugins.java @@ -0,0 +1,70 @@ +package com.actionsoft.apps.coe.pal.output.or; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.actionsoft.apps.coe.pal.output.or.dc.OutputDCFileProcessor; +import com.actionsoft.apps.coe.pal.output.or.report1.Report1Gener; +import com.actionsoft.apps.coe.pal.output.or.report1.Report1WizardOption; +import com.actionsoft.apps.coe.pal.output.or.report2.Report2Gener; +import com.actionsoft.apps.coe.pal.output.or.report2.Report2WizardOption; +import com.actionsoft.apps.coe.pal.pal.output.constant.OutputConst; +import com.actionsoft.apps.listener.PluginListener; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.apps.resource.plugin.profile.AWSPluginProfile; +import com.actionsoft.apps.resource.plugin.profile.AppExtensionProfile; +import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; +import com.alibaba.fastjson.JSONArray; + +public class Plugins implements PluginListener { + + public Plugins() { + } + + @Override + public List register(AppContext arg0) { + List list = new ArrayList(); + list.add(new DCPluginProfile(OutputConst.EXT_APP_DC_OUTPUT, OutputDCFileProcessor.class.getName(), "存放生成的报告文件", false, false)); + list.add(new DCPluginProfile("tmp", OutputDCFileProcessor.class.getName(), "存放下载的zip临时文件", false)); + + // 注册应用扩展点 + Map params1 = new HashMap(); + params1.put("groupName", "岗位手册"); + params1.put("title", "岗位手册-横表"); + params1.put("targetMethodScope", "org.normal");// 建模大类、建模方法,多个用逗号隔开,如果为空表示全部 + params1.put("targetMethodType", "organization,position,role,employee");// 建模方法中的图元,为空表示只选择文件,不选择图元;为"-"表示所有类型图元 + params1.put("relationMethodScope", "process.bpmn2,process.epc,process.flowchart");// 如果设置-,表示不需要用户选择关联范围,向导页被忽略 + params1.put("lang", "cn");// 该App支持的语言,多个用逗号隔开 + params1.put("optionClass", Report1WizardOption.class.getName());// 附加的报表选项,如果该值没有,向导页被忽略 + params1.put("generClass", Report1Gener.class.getName());// 生成报告 + // 模版上传下载参数 + params1.put("isDownload", true); + JSONArray array1 = new JSONArray(); + array1.add("横表-岗位手册.doc"); + array1.add("横表-岗位手册.xml"); + params1.put("templates", array1.toString()); + list.add(new AppExtensionProfile("PAL报告->岗位手册-横表", "aslp://com.actionsoft.apps.coe.pal/registerOutputApp", params1)); + + Map params2 = new HashMap(); + params2.put("groupName", "岗位手册"); + params2.put("title", "岗位手册-竖表"); + params2.put("targetMethodScope", "org.normal");// 建模大类、建模方法,多个用逗号隔开,如果为空表示全部 + params2.put("targetMethodType", "organization,position,role,employee");// 建模方法中的图元,为空表示只选择文件,不选择图元;为"-"表示所有类型图元 + params2.put("relationMethodScope", "process.bpmn2,process.epc,process.flowchart");// 如果设置-,表示不需要用户选择关联范围,向导页被忽略 + params2.put("lang", "cn");// 该App支持的语言,多个用逗号隔开 + params2.put("optionClass", Report2WizardOption.class.getName());// 附加的报表选项,如果该值没有,向导页被忽略 + params2.put("generClass", Report2Gener.class.getName());// 生成报告 + // 模版上传下载参数 + params2.put("isDownload", true); + JSONArray array2 = new JSONArray(); + array2.add("竖表-岗位手册.doc"); + array2.add("竖表-岗位手册.xml"); + params2.put("templates", array2.toString()); + list.add(new AppExtensionProfile("PAL报告->岗位手册-竖表", "aslp://com.actionsoft.apps.coe.pal/registerOutputApp", params2)); + + return list; + } + +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/ReportORController.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/ReportORController.java new file mode 100644 index 00000000..69155223 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/ReportORController.java @@ -0,0 +1,96 @@ +package com.actionsoft.apps.coe.pal.output.or; + +import com.actionsoft.apps.coe.pal.pal.output.OutPutReportWeb; +import com.actionsoft.apps.coe.pal.pal.output.OutputAPIManager; +import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask; +import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel; +import com.alibaba.fastjson.JSONObject; + +import com.actionsoft.apps.coe.pal.output.or.dc.OutputDCFileProcessor; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.server.bind.annotation.Controller; +import com.actionsoft.bpms.server.bind.annotation.Mapping; + + +/** +* @Description 岗位手册Controller类 +* @author zhangming +* @date 2014年11月10日 +* +*/ +@Controller +public class ReportORController { + /** + * 报告小载 + * + * @param me + * @param id + * @return + */ + @Mapping("com.actionsoft.apps.coe.pal.output.or_downloadreport") + public String downloadReport(UserContext me, String id) { + OutputTaskModel model = new OutputTask().getTaskReportById(id); + ResponseObject ro = null; + JSONObject json = new JSONObject(); + if (model != null) { + try { + ro = ResponseObject.newOkResponse(); + json.put("url", OutputDCFileProcessor.getReportDownloadURL(model.getWsId(), id, model.getProfileId(), me, model.getTaskName())); + ro.setData(json); + } catch (Exception e) { + ro = ResponseObject.newErrResponse(); + e.printStackTrace(); + } + } + return ro.toString(); + } + + @Mapping("com.actionsoft.apps.coe.pal.output.or_downloadlog") + /**日志下载 + * + * @param me + * @param wsid + * @return + */ + public String downloadLog(UserContext me, String id) { + OutputTaskModel model = new OutputTask().getTaskReportById(id); + ResponseObject ro = null; + JSONObject json = new JSONObject(); + if (model != null) { + try { + ro = ResponseObject.newOkResponse(); + json.put("url", OutputDCFileProcessor.getReportLogDownloadURL(model.getWsId(), id, model.getProfileId(), me, model.getTaskName())); + ro.setData(json); + } catch (Exception e) { + ro = ResponseObject.newErrResponse(); + e.printStackTrace(); + } + } + return ro.toString(); + } + + @Mapping("com.actionsoft.apps.coe.pal.output.or_clonetask") + /**报告克隆 + * + * @param me + * @param wsid + * @return + */ + public String cloneTask(UserContext me, String id, String teamId, String wsid) { + ResponseObject ro = null; + try { + OutputAPIManager.getInstance().cloneTask(me.getUID(), id); + OutPutReportWeb outPutReport = new OutPutReportWeb(me); + int total = outPutReport.getCountTotal(wsid, teamId); + JSONObject json = new JSONObject(); + json.put("totalPage", total); + ro = ResponseObject.newOkResponse(); + ro.setData(json); + } catch (Exception e) { + ro = ResponseObject.newErrResponse(); + e.printStackTrace(); + } + return ro.toString(); + } +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/dc/OutputDCFileProcessor.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/dc/OutputDCFileProcessor.java new file mode 100644 index 00000000..3d6d34e2 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/dc/OutputDCFileProcessor.java @@ -0,0 +1,79 @@ +package com.actionsoft.apps.coe.pal.output.or.dc; + +import java.io.File; + +import com.actionsoft.apps.AppsConst; +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI; +import com.actionsoft.apps.coe.pal.log.CoEOpLogConst; +import com.actionsoft.apps.coe.pal.pal.output.OutputAPIManager; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.server.fs.AbstFileProcessor; +import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.server.fs.FileProcessorListener; +import com.actionsoft.bpms.server.fs.dc.DCUtil; +import com.actionsoft.bpms.util.UtilFile; +import com.actionsoft.sdk.local.SDK; + +/** +* @Description 文件库操作处理 +* @author zhangming +* @date 2014年10月29日 +* +*/ +public class OutputDCFileProcessor extends AbstFileProcessor implements FileProcessorListener { + /** + * 得到报告文件 + * + * @param wsId 资产库id + * @param id 任务Id + * @param profileId 报告生成器扩展App的配置Id + * @throws Exception + */ + public static String getReportDownloadURL(String wsId, String id, String profileId, UserContext _uc, String taskName) throws Exception { + UtilFile file = OutputAPIManager.getInstance().getFilePath(wsId, id, profileId); + if (file.exists()) { + //String josnStr = OutputAPIManager.getInstance().getWizardJsonData(wsId, id, profileId); + // JSONObject jsonObj = JSONObject.fromObject(josnStr); + DCContext dcContext = null; + DCUtil.getInstance(); + dcContext = DCUtil.createTempFileContext("com.actionsoft.apps.coe.pal.output.or", "output", id, "zip"); + dcContext.setFileName(taskName+ ".zip"); + File ff = new File(dcContext.getFilePath()); + UtilFile.zipCompress(file.getPath(), ff, "doc"); + dcContext.setSession(_uc); + // 操作行为日志记录 + if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) { + CoEOpLogAPI.auditOkOp(_uc, CoEOpLogConst.MODULE_CATEGORY_APPCENTER, CoEOpLogConst.OP_DOWNLOAD, CoEOpLogConst.INFO_OUTPUT_DOWNLOAD); + } + return dcContext.getDownloadURL(); + } + return ""; + } + + /** + * 得到日志文件 + * + * @param wsId 资产库id + * @param id 任务Id + * @param profileId 报告生成器扩展App的配置Id + * @throws Exception + */ + public static String getReportLogDownloadURL(String wsId, String id, String profileId, UserContext _uc, String taskName) throws Exception { + UtilFile file = OutputAPIManager.getInstance().getFilePath(wsId, id, profileId); + if (file.exists()) { + DCContext dcContext = null; + dcContext = DCUtil.getInstance().createTempFileContext("com.actionsoft.apps.coe.pal.output.or", "output", id, "zip"); + dcContext.setFileName("log.zip"); + File ff = new File(dcContext.getFilePath()); + UtilFile.zipCompress(file.getPath(), ff, "log"); + dcContext.setSession(_uc); + // 操作行为日志记录 + if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) { + CoEOpLogAPI.auditOkOp(_uc, CoEOpLogConst.MODULE_CATEGORY_APPCENTER, CoEOpLogConst.OP_DOWNLOAD, CoEOpLogConst.INFO_OUTPUT_DOWNLOAD_LOG); + } + return dcContext.getDownloadURL(); + } + return ""; + } +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report1/Report1Gener.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report1/Report1Gener.java new file mode 100644 index 00000000..e6a9fee1 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report1/Report1Gener.java @@ -0,0 +1,394 @@ +package com.actionsoft.apps.coe.pal.output.or.report1; + +import java.util.*; + +import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel; +import com.actionsoft.apps.coe.pal.pal.output.extend.GenerLogExd; +import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager; +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.dao.CoeProcessLevelDaoFacotory; +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.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import com.actionsoft.apps.coe.pal.output.or.util.OrReportComment; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.org.model.RoleModel; +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; + +/** + * 生成岗位手册-横表的入口 + * + * @author zhangming + */ +public class Report1Gener { + // 防止生成过程中,停用或卸载该app + public static boolean isRunning = false; + public static final Object _lock = new Object(); + GenerLogExd log = new GenerLogExd(); + public Report1Gener() { + } + + /** + * 生成文件 + * + * @param model OutputTaskModel对象 + * @param wizardJsonData 向导收集的Json参数(targetFiles、relationFiles、options...) + * @param dcContext 要生成报告的DC目录对象,已准备好 + * @return 将文件生成到output目录下,返回状态 + * + * @see PlatformAPIImpl#getDefaultLanguage() + * @see PlatformAPIImpl#getlanguages() + */ + public ResponseObject execute(OutputTaskModel model, String wizardJsonData, DCContext dcContext) { + try { + synchronized (_lock) { + isRunning = true; + String teamId = model.getTeamId(); + String wsId = model.getWsId(); + log.info("execute ready..."); + log.info("-------------------"); + log.info("TeamId=" + teamId); + log.info("wsId=" + wsId); + JSONObject jsonObj = JSONObject.parseObject(wizardJsonData); + log.info("dcPath=" + dcContext.getPath()); + // ----预处理、校验---- + OutputAppProfile appModel = OutputAppManager.getProfile(model.getProfileId()); + String tempPath = appModel.getAppContext().getPath(); + String tempName = "横表-岗位手册.xml"; + log.info("begin..."); + log.info("-------------------"); + // ----文件处理----- + String targetFileIds = jsonObj.getString("targetFileId"); + if (!UtilString.isEmpty(targetFileIds)) { + if (isJsonArray(targetFileIds)) { + JSONArray array = JSONArray.parseArray(targetFileIds); + genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj, array); + } else { + genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj); + } + } + log.info("end"); + } + } finally { + isRunning = false; + } + return ResponseObject.newOkResponse().put("logs", log.logs()); + } + + private boolean isJsonArray(String str) { + try { + JSONArray.parseArray(str); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 循环生成多份报告 + * + * @param tempPath + * @param tempName + * @param docPath + * @param wizardJsonData + */ + private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData) { + String[] targetShapes = wizardJsonData.getString("targetShape").split(","); + String[] repositoryIds = wizardJsonData.getString("targetFileId").split(","); + String repositoryId = null; + for (String id : repositoryIds) { + if (!"".equals(id)) { + repositoryId = id; + break; + } + } + List> list = CoeDesignerUtil.getShapeMessageJson(repositoryId); // 指定流程文件内容 + if (list == null) { + return; + } + Map> shapesMap = new HashMap>(); + List> linkerList = new ArrayList>(); + for (Map map : list) { + if ("linker".equals(map.get("name"))) { + linkerList.add(map); + } else { + shapesMap.put((String) map.get("id"), map); + } + } + + Map indexMap = new HashMap(); + String reportName = wizardJsonData.getString("reportNameIsItName"); + for (String targetShapeId : targetShapes) { + if (targetShapeId == null || "".equals(targetShapeId)) { + continue; + } + Map shapeMap = shapesMap.get(targetShapeId); + String shapeName = ""; + if (shapeMap != null) { + shapeName = shapeMap.get("text").toString().replaceAll("\n", "_"); + } + shapeName = reportName.replaceAll("%shapeName%", shapeName); + shapeName = shapeName.replaceAll(OutputExcelUtil.FILENAMEREGX, ""); + if (shapeName.length() > 255) { + shapeName = shapeName.substring(0, 255); + } + String docName = ""; + if (indexMap.containsKey(shapeName)) { + int index = indexMap.get(shapeName); + index++; + log.info("得到word名称为:" + shapeName + "(" + index + ")"); + docName = docPath + shapeName + "(" + index + ")" + ".doc"; + indexMap.put(shapeName, index); + } else { + log.info("得到word名称为:" + shapeName); + docName = docPath + shapeName + ".doc"; + indexMap.put(shapeName, 1); + } + + JSONObject dataMap = getData(targetShapeId, shapesMap, linkerList, wizardJsonData); + OutputWordUtil.createDoc(dataMap, tempPath, tempName, docName); + } + } + + /** + * 获取报告中所需数据 + * + * @param shapeId + * @param shapesMap + * @param linkerList + * @param wizardJsonData + * @return + */ + private JSONObject getData(String shapeId, Map> shapesMap, List> linkerList, JSONObject wizardJsonData) { + + JSONObject dataMap = new JSONObject(); + + OrReportComment orReportComment = new OrReportComment(); + orReportComment.getCommentContent(dataMap, shapesMap, shapeId); // 获取一些公共的数据(手册首页的手册岗位名称、部门、时间等) + + // 流程表格 + JSONArray _table = new JSONArray(); + String[] relationFileIds = wizardJsonData.getString("relationFileId").split(","); // 关联文件Id数组 + DesignerShapeRelationDao dao = new DesignerShapeRelationDao(); + // 循环关联文件 + int index = 1; + for (String relationFileId : relationFileIds) { + if (relationFileId.equals("")) { + continue; + } + 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()); + } + + 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_NAME, shapeMap.get("text").toString().replace("\n", OutputWordUtil.WRAPSTRING)); // 步骤名称 + + 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)); + } + } + _table.add(_tr); + index++; + } + } + } + + if (_table.size() == 0) { + _table = getEmptyTable("process.bpmn2"); + } + + dataMap.put(OutputWordUtil.TABLE_REPOSITORY, _table); + return dataMap; + } + + private JSONArray getEmptyTable(String methodId) { + JSONArray table = new JSONArray(); + JSONObject _tr = new JSONObject(); + PALMethodModel palMethodModel = PALMethodCache.getPALMethodModelById(methodId); + _tr.put(OutputWordUtil.SHAPE_NAME, ""); + _tr.put(OutputWordUtil.SHAPE_NUMBER, ""); + _tr.put(OutputWordUtil.REPOSITORY_NAME, ""); // 流程名称 + _tr.put(OutputWordUtil.SERIAL_NUMBER, ""); + _tr.put(OutputWordUtil.SHAPE_DESC, ""); // 工作详细描述 + List attributes = palMethodModel.getAttributes(); + if (attributes != null) { + for (PALMethodAttributeModel attribute : attributes) { + String scope = attribute.getScope(); + if (!"%".equals(scope)) { + _tr.put("shape_" + attribute.getKey(), ""); + } + } + } + table.add(_tr); + return table; + } + + /**********************关联AWS组织的excel处理***************************/ + /** + * 循环生成多份报告 + * + * @param tempPath + * @param tempName + * @param docPath + * @param wizardJsonData + */ + private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData, JSONArray targetFileIds) { + // 按照名称排序 + List roleList = new ArrayList<>(); + for (int i = 0; i < targetFileIds.size(); i++) { + JSONObject object = targetFileIds.getJSONObject(i); + RoleModel model = SDK.getORGAPI().getRoleById(object.getString("id")); + if (model != null) { + roleList.add(model); + } + // sort + Collections.sort(roleList, new Comparator() { + @Override + public int compare(RoleModel role1, RoleModel role2) { + return role1.getOrderIndex() - role2.getOrderIndex(); + } + }); + } + + Map indexMap = new HashMap(); + String reportName = wizardJsonData.getString("reportNameIsItName"); + for (RoleModel role : roleList) { + String shapeName = ""; + shapeName = role.getName().replaceAll("\n", "_"); + shapeName = reportName.replaceAll("%shapeName%", shapeName); + shapeName = shapeName.replaceAll(OutputExcelUtil.FILENAMEREGX, ""); + if (shapeName.length() > 255) { + shapeName = shapeName.substring(0, 255); + } + String docName = ""; + if (indexMap.containsKey(shapeName)) { + int index = indexMap.get(shapeName); + index++; + log.info("得到word名称为:" + shapeName + "(" + index + ")"); + docName = docPath + shapeName + "(" + index + ")" + ".doc"; + indexMap.put(shapeName, index); + } else { + log.info("得到word名称为:" + shapeName); + docName = docPath + shapeName + ".doc"; + indexMap.put(shapeName, 1); + } + + JSONObject dataMap = getData(role, wizardJsonData); + OutputWordUtil.createDoc2(dataMap, tempPath, tempName, docName); + } + } + + /** + * 获取报告中所需数据 + * @param role + * @param wizardJsonData + * @return + */ + private JSONObject getData(RoleModel role, JSONObject wizardJsonData) { + + JSONObject dataMap = new JSONObject(); + + OrReportComment orReportComment = new OrReportComment(); + orReportComment.getAwsOrgCommentContent(dataMap, role); // 获取一些公共的数据(手册首页的手册岗位名称、部门、时间等) + + // 流程表格 + JSONArray _table = new JSONArray(); + String[] relationFileIds = wizardJsonData.getString("relationFileId").split(","); // 关联文件Id数组 + DesignerShapeRelationDao dao = new DesignerShapeRelationDao(); + // 循环关联文件 + int index = 1; + for (String relationFileId : relationFileIds) { + if (relationFileId.equals("")) { + continue; + } + List relationModelList = dao.getModelListByRelationShapeId(relationFileId, "00000000-0000-0000-0000-000000000000"); // 关联信息 + 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()); + } + if (wizardJsonData.getBoolean("orderNuberFirst")) { + OutputWordUtil.orderByNumber(relationFileElements); + } + + 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_NAME, shapeMap.get("text").toString().replace("\n", OutputWordUtil.WRAPSTRING)); // 步骤名称 + + 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)); + } + } + _table.add(_tr); + index++; + } + } + } + + if (_table.size() == 0) { + _table = getEmptyTable("process.bpmn2"); + } + + dataMap.put(OutputWordUtil.TABLE_REPOSITORY, _table); + return dataMap; + } + /**********************关联AWS组织的excel处理***************************/ + +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report1/Report1WizardOption.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report1/Report1WizardOption.java new file mode 100644 index 00000000..d744ea42 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report1/Report1WizardOption.java @@ -0,0 +1,32 @@ +package com.actionsoft.apps.coe.pal.output.or.report1; + +import com.actionsoft.bpms.commons.mvc.view.ActionWeb; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.sdk.local.api.internal.PlatformAPIImpl; + +/** + * 向导收集该报告的特定选项 + * + */ +public class Report1WizardOption extends ActionWeb { + + public Report1WizardOption(UserContext userContext) { + super(userContext); + } + + public Report1WizardOption() { + } + + /** + * 实现约定的getOption方法 + * + * @param teamId 小组Id + * @param wsId 资产库Id + * @param lang 语言 + * @param wizardJsonData 向导收集的Json参数(targetFiles、relationFiles...) + * @return 含有回调js的html片段 + */ + public String getOption(String teamId, String wsId, String lang, String wizardJsonData) { + return "hi! OR"; + } +} 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 new file mode 100644 index 00000000..85004cd3 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2Gener.java @@ -0,0 +1,566 @@ +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 com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel; +import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel; +import com.actionsoft.apps.coe.pal.pal.output.extend.GenerLogExd; +import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager; +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.dao.CoeProcessLevelDaoFacotory; +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.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import com.actionsoft.apps.coe.pal.output.or.util.OrReportComment; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.org.model.RoleModel; +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; + +/** + * 生成岗位手册-横表的入口 + * + * @author zhangming + */ +public class Report2Gener { + // 防止生成过程中,停用或卸载该app + public static boolean isRunning = false; + public static final Object _lock = new Object(); + GenerLogExd log = new GenerLogExd(); + + public Report2Gener() { + } + + /** + * 生成文件 + * + * @param model OutputTaskModel对象 + * @param wizardJsonData 向导收集的Json参数(targetFiles、relationFiles、options...) + * @param dcContext 要生成报告的DC目录对象,已准备好 + * @return 将文件生成到output目录下,返回状态 + * + * @see PlatformAPIImpl#getDefaultLanguage() + * @see PlatformAPIImpl#getlanguages() + */ + public ResponseObject execute(OutputTaskModel model, String wizardJsonData, DCContext dcContext) { + try { + synchronized (_lock) { + isRunning = true; + String teamId = model.getTeamId(); + String wsId = model.getWsId(); + log.info("execute ready..."); + log.info("-------------------"); + log.info("TeamId=" + teamId); + log.info("wsId=" + wsId); + JSONObject jsonObj = JSONObject.parseObject(wizardJsonData); + log.info("dcPath=" + dcContext.getPath()); + // ----预处理、校验---- + OutputAppProfile appModel = OutputAppManager.getProfile(model.getProfileId()); + String tempPath = appModel.getAppContext().getPath(); + String tempName = "竖表-岗位手册.xml"; + log.info("begin..."); + log.info("-------------------"); + // ----文件处理----- + String targetFileIds = jsonObj.getString("targetFileId"); + if (!UtilString.isEmpty(targetFileIds)) { + if (isJsonArray(targetFileIds)) { + JSONArray array = JSONArray.parseArray(targetFileIds); + genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj, array); + } else { + genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj); + } + } + log.info("end"); + } + } finally { + isRunning = false; + } + return ResponseObject.newOkResponse().put("logs", log.logs()); + } + + private boolean isJsonArray(String str) { + try { + JSONArray.parseArray(str); + return true; + } catch (Exception e) { + return false; + } + } + + private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData) { + String[] targetShapes = wizardJsonData.getString("targetShape").split(","); + String[] repositoryIds = wizardJsonData.getString("targetFileId").split(","); + String repositoryId = null; + for (String id : repositoryIds) { + if (!"".equals(id)) { + repositoryId = id; + break; + } + } + List> list = CoeDesignerUtil.getShapeMessageJson(repositoryId); // 指定流程文件内容 + if (list == null) { + return; + } + Map> shapesMap = new HashMap>(); + List> linkerList = new ArrayList>(); + for (Map map : list) { + if ("linker".equals(map.get("name"))) { + linkerList.add(map); + } else { + shapesMap.put((String) map.get("id"), map); + } + } + + String reportName = wizardJsonData.getString("reportNameIsItName"); + Map indexMap = new HashMap(); + for (String targetShapeId : targetShapes) { + if (targetShapeId == null || "".equals(targetShapeId)) { + continue; + } + Map shapeMap = shapesMap.get(targetShapeId); + String shapeName = ""; + if (shapeMap != null) { + shapeName = shapeMap.get("text").toString().replaceAll("\n", "_"); + } + shapeName = reportName.replaceAll("%shapeName%", shapeName); + shapeName = shapeName.replaceAll(OutputExcelUtil.FILENAMEREGX, ""); + if (shapeName.length() > 255) { + shapeName = shapeName.substring(0, 255); + } + + String docName = ""; + if (indexMap.containsKey(shapeName)) { + int index = indexMap.get(shapeName); + index++; + log.info("得到word名称为:" + shapeName + "(" + index + ")"); + docName = docPath + shapeName + "(" + index + ")" + ".doc"; + indexMap.put(shapeName, index); + } else { + log.info("得到word名称为:" + shapeName); + docName = docPath + shapeName + ".doc"; + indexMap.put(shapeName, 1); + } + + JSONObject dataMap = getData(targetShapeId, shapesMap, linkerList, wizardJsonData); + OutputWordUtil.createDoc(dataMap, tempPath, tempName, docName); + } + } + + private JSONObject getData(String shapeId, Map> shapesMap, + List> linkerList, JSONObject wizardJsonData) { + + JSONObject dataMap = new JSONObject(); + + OrReportComment orReportComment = new OrReportComment(); + orReportComment.getCommentContent(dataMap, shapesMap, shapeId); //获取一些公共的数据(手册首页的手册岗位名称、部门、公司、时间、岗位职责等) + + //流程表格 + JSONArray repositoryTable = new JSONArray(); //相关流程 + JSONArray repositoryShapeTable = new JSONArray(); //流程步骤 + JSONArray institutionTable = new JSONArray(); //相关制度 + JSONArray formTable = new JSONArray(); //相关表单 + JSONArray itsystemTable = new JSONArray(); //相关IT系统 + JSONArray KPITable = new JSONArray(); //相关绩效考核 + + //循环关联文件 + List repositoryNameList = new ArrayList(); + Set institutionSet = new HashSet(); + 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; + } + + 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()); + } + + 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)); //步骤名称 + + 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)); + } + } + repositoryShapeTable.add(_tr); + if (!repositoryNameList.contains(relationModel.getName())) { + repositoryNameList.add(relationModel.getName()); + } + if (!map.containsKey(relationModel.getId())) { + map.put(relationModel.getId(), new ArrayList()); + } + map.get(relationModel.getId()).add(id); + index++; + } + } + } + + //相关流程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); + } + } + + dataMap.put(OutputWordUtil.TABLE_REPOSITORY, repositoryTable); + dataMap.put(OutputWordUtil.TABLE_REPOSITORY_SHAPE, repositoryShapeTable); + + // 完善部分表格信息 + updateOtherTableInfo(dataMap, institutionTable, formTable, itsystemTable, KPITable); + + return dataMap; + } + + /** + * 完善部分信息 + * @param dataMap + * @param institutionTable + * @param formTable + * @param itsystemTable + * @param KPITable + */ + private void updateOtherTableInfo(JSONObject dataMap, JSONArray institutionTable, JSONArray formTable, JSONArray itsystemTable, JSONArray KPITable) { + //制度 + if (institutionTable.size() == 0) { + institutionTable = getEmptyTable("control.policy"); + } + dataMap.put(OutputWordUtil.TABLE_INSTITUTION, institutionTable); + //表单 + if (formTable.size() == 0) { + formTable = getEmptyTable("data.form"); + } + dataMap.put(OutputWordUtil.TABLE_FORM, formTable); + //it系统 + if (itsystemTable.size() == 0) { + itsystemTable = getEmptyTable("itsystem.normal"); + } + dataMap.put(OutputWordUtil.TABLE_IT_SYSTEM, itsystemTable); + //绩效考核 + if (KPITable.size() == 0) { + KPITable = getEmptyTable("control.kpi"); + } + dataMap.put(OutputWordUtil.TABLE_KPI, KPITable); + + // 序号处理SERIAL_NUMBER + for (int j = 0; j < institutionTable.size(); j++) { + institutionTable.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); + } + + for (int j = 0; j < itsystemTable.size(); j++) { + itsystemTable.getJSONObject(j).put(OutputWordUtil.SERIAL_NUMBER, j + 1); + } + + for (int j = 0; j < KPITable.size(); j++) { + KPITable.getJSONObject(j).put(OutputWordUtil.SERIAL_NUMBER, j + 1); + } + } + + private void getRelationData(JSONArray table, String attrId, String fileId, String shapeId, Set idSet, DesignerShapeRelationDao dao, Map>> recordsMap) { + List institutionList = dao.query(fileId, shapeId, attrId, null, null); + if (institutionList != null && institutionList.size() > 0) { + for (DesignerShapeRelationModel model : institutionList) { + if (UtilString.isEmpty(model.getRelationShapeId())) { + continue; + } + if (idSet.contains(model.getRelationShapeId())) { + continue; + } + idSet.add(model.getRelationShapeId()); + + if (!recordsMap.containsKey(model.getRelationFileId())) { + List> elements = CoeDesignerUtil.getShapeMessageJson4(model.getRelationFileId()); // 关联流程文件内容 + recordsMap.put(model.getRelationFileId(), elements); + } + List> elements = recordsMap.get(model.getRelationFileId()); + for (Map shapeMap : elements) { + if (model.getRelationShapeId().equals(shapeMap.get("id").toString())) { + + JSONObject _tr = new JSONObject(); + OutputWordUtil.setShapeDefaultValue2(model.getRelationFileId(), _tr); + _tr.put(OutputWordUtil.SHAPE_ID, shapeMap.get("id")); //步骤元素id + _tr.put(OutputWordUtil.SHAPE_NAME, shapeMap.get("text").toString().replace("\n", OutputWordUtil.WRAPSTRING)); //步骤名称 + JSONArray dataAttributes = (JSONArray) shapeMap.get("attributes"); + if (!dataAttributes.isEmpty()) { + for (int j = 0; j < dataAttributes.size(); j++) { + JSONObject obj = dataAttributes.getJSONObject(j); + String key = obj.getString("key"); + String attrValue = obj.getString("value"); + _tr.put("shape_" + key, attrValue.replace("\n", OutputWordUtil.WRAPSTRING)); + } + } + table.add(_tr); + } + } + } + } + + } + + private JSONArray getEmptyTable(String methodId) { + JSONArray table = new JSONArray(); + JSONObject _tr = new JSONObject(); + PALMethodModel palMethodModel = PALMethodCache.getPALMethodModelById(methodId); + _tr.put(OutputWordUtil.SHAPE_NAME, ""); + _tr.put(OutputWordUtil.SHAPE_NUMBER, ""); + _tr.put(OutputWordUtil.REPOSITORY_NAME, ""); //流程名称 + _tr.put(OutputWordUtil.SERIAL_NUMBER, ""); + _tr.put(OutputWordUtil.SHAPE_DESC, ""); //工作详细描述 + List attributes = palMethodModel.getAttributes(); + if (attributes != null) { + for (PALMethodAttributeModel attribute : attributes) { + String scope = attribute.getScope(); + if (!"%".equals(scope)) { + _tr.put("shape_" + attribute.getKey(), ""); + } + } + } + table.add(_tr); + return table; + } + + /**********************关联AWS组织的excel处理***************************/ + + private void genarateWord(String tempPath, String tempName, String docPath, JSONObject wizardJsonData, JSONArray targetFileIds) { + // 按照名称排序 + List roleList = new ArrayList<>(); + for (int i = 0; i < targetFileIds.size(); i++) { + JSONObject object = targetFileIds.getJSONObject(i); + RoleModel model = SDK.getORGAPI().getRoleById(object.getString("id")); + if (model != null) { + roleList.add(model); + } + // sort + Collections.sort(roleList, new Comparator() { + @Override + public int compare(RoleModel role1, RoleModel role2) { + return role1.getOrderIndex() - role2.getOrderIndex(); + } + }); + } + + String reportName = wizardJsonData.getString("reportNameIsItName"); + Map indexMap = new HashMap(); + for (RoleModel role : roleList) { + String shapeName = ""; + shapeName = role.getName().replaceAll("\n", "_"); + shapeName = reportName.replaceAll("%shapeName%", shapeName); + shapeName = shapeName.replaceAll(OutputExcelUtil.FILENAMEREGX, ""); + if (shapeName.length() > 255) { + shapeName = shapeName.substring(0, 255); + } + + String docName = ""; + if (indexMap.containsKey(shapeName)) { + int index = indexMap.get(shapeName); + index++; + log.info("得到word名称为:" + shapeName + "(" + index + ")"); + docName = docPath + shapeName + "(" + index + ")" + ".doc"; + indexMap.put(shapeName, index); + } else { + log.info("得到word名称为:" + shapeName); + docName = docPath + shapeName + ".doc"; + indexMap.put(shapeName, 1); + } + + JSONObject dataMap = getData(role, wizardJsonData); + OutputWordUtil.createDoc(dataMap, tempPath, tempName, docName); + } + } + + private JSONObject getData(RoleModel role, JSONObject wizardJsonData) { + + JSONObject dataMap = new JSONObject(); + + OrReportComment orReportComment = new OrReportComment(); + orReportComment.getAwsOrgCommentContent(dataMap, role); //获取一些公共的数据(手册首页的手册岗位名称、部门、公司、时间、岗位职责等) + + //流程表格 + JSONArray repositoryTable = new JSONArray(); //相关流程 + JSONArray repositoryShapeTable = new JSONArray(); //流程步骤 + JSONArray institutionTable = new JSONArray(); //相关制度 + JSONArray formTable = new JSONArray(); //相关表单 + JSONArray itsystemTable = new JSONArray(); //相关IT系统 + JSONArray KPITable = new JSONArray(); //相关绩效考核 + + //循环关联文件 + List repositoryNameList = new ArrayList(); + Set institutionSet = new HashSet(); + 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; + } + + List relationModelList = dao.getModelListByRelationShapeId(relationFileId, "00000000-0000-0000-0000-000000000000"); // 关联信息 + 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()); + } + + 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)); //步骤名称 + + 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)); + } + } + repositoryShapeTable.add(_tr); + if (!repositoryNameList.contains(relationModel.getName())) { + repositoryNameList.add(relationModel.getName()); + } + if (!map.containsKey(relationModel.getId())) { + map.put(relationModel.getId(), new ArrayList()); + } + map.get(relationModel.getId()).add(id); + index++; + } + } + } + + //相关流程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); + } + } + + dataMap.put(OutputWordUtil.TABLE_REPOSITORY, repositoryTable); + dataMap.put(OutputWordUtil.TABLE_REPOSITORY_SHAPE, repositoryShapeTable); + + // 完善部分表格信息 + updateOtherTableInfo(dataMap, institutionTable, formTable, itsystemTable, KPITable); + + return dataMap; + } + + /**********************关联AWS组织的excel处理***************************/ + +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2WizardOption.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2WizardOption.java new file mode 100644 index 00000000..0d6d8e7c --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/report2/Report2WizardOption.java @@ -0,0 +1,35 @@ +package com.actionsoft.apps.coe.pal.output.or.report2; + +import com.actionsoft.bpms.commons.mvc.view.ActionWeb; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.sdk.local.api.internal.PlatformAPIImpl; + +/** + * 向导收集该报告的特定选项 + * + */ +public class Report2WizardOption extends ActionWeb { + + public Report2WizardOption(UserContext userContext) { + super(userContext); + } + + public Report2WizardOption() { + } + + /** + * 实现约定的getOption方法 + * + * @param teamId 小组Id + * @param wsId 资产库Id + * @param lang 语言 + * @param wizardJsonData 向导收集的Json参数(targetFiles、relationFiles...) + * @return 含有回调js的html片段 + * + * @see PlatformAPIImpl#getDefaultLanguage() + * @see PlatformAPIImpl#getlanguages() + */ + public String getOption(String teamId, String wsId, String lang, String wizardJsonData) { + return "hi! OR"; + } +} diff --git a/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/util/OrReportComment.java b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/util/OrReportComment.java new file mode 100644 index 00000000..1df51db2 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.output.or/src/com/actionsoft/apps/coe/pal/output/or/util/OrReportComment.java @@ -0,0 +1,134 @@ +package com.actionsoft.apps.coe.pal.output.or.util; + +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil; +import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.designer.util.ShapeUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.actionsoft.bpms.org.cache.UserCache; +import com.actionsoft.bpms.org.cache.UserMapCache; +import com.actionsoft.bpms.org.model.DepartmentModel; +import com.actionsoft.bpms.org.model.RoleModel; +import com.actionsoft.bpms.org.model.UserMapModel; +import com.actionsoft.bpms.org.model.UserModel; +import com.actionsoft.sdk.local.SDK; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; +import org.apache.commons.lang.StringUtils; + +public class OrReportComment { + + public void getCommentContent(JSONObject dataMap, Map> shapesMap, String shapeId) { + Map shapeMap = shapesMap.get(shapeId); + dataMap.put(OutputWordUtil.POSITION, shapeMap.get("name").toString().replace("\n", "")); //岗位名称 + //TODO 所属部门/公司 + String messageJson = PALRepositoryQueryAPIManager.getInstance().getProcessDefinition(null, shapeMap.get("pid").toString()); + JSONObject definition = JSONObject.parseObject(messageJson); + JSONObject elements = definition.getJSONObject("elements"); + List deptNames = Lists.newArrayList(); + if (StringUtils.isNotEmpty(messageJson)) { + JSONArray array = ShapeUtil.getLinker(messageJson); + for (int i = 0; i < array.size(); i++) { + JSONObject tmpObj = array.getJSONObject(i); + String toShapeId = tmpObj.getString("to"); + if (toShapeId.equals(shapeId)) { + deptNames.add(getDeptName(array, tmpObj, elements)); + } + } + } + String deptName = ""; + if (deptNames.size() > 0) { + deptName = Joiner.on(",").join(deptNames); + } + dataMap.put(OutputWordUtil.DEPARTMENT, deptName); //所属部门 + dataMap.put("role_department", deptName);// 所属部门 + dataMap.put(OutputWordUtil.COMPANY, "公司"); //所属公司 + //创建日期 + Timestamp nowTime = new Timestamp(System.currentTimeMillis()); + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + dataMap.put(OutputWordUtil.GENERATEDATE, sdf.format(nowTime)); + //岗位职责 + JSONArray attributesJsonArray = (JSONArray) ((JSONObject)shapeMap.get("attributes")).get("attributesJsonArray"); + String dutie = ""; + if (attributesJsonArray != null) { + for (int i = 0; i < attributesJsonArray.size(); i++) { + JSONObject attribute = attributesJsonArray.getJSONObject(i); + if (OutputWordUtil.ORGDUTIE.equals(attribute.getString("id"))) { + dutie = attribute.getString("value"); + break; + } + } + } + dataMap.put(OutputWordUtil.ORGDUTIE, dutie); + } + + public String getDeptName(JSONArray array, JSONObject tmpObj, JSONObject elements) { + String fromShapeId = tmpObj.getString("from"); + JSONObject shape = elements.getJSONObject(fromShapeId); + if (shape.getString("title").equals("组织")) { + return shape.getString("text"); + } else { + JSONObject tempFromObj = null; + for (int i = 0; i < array.size(); i++) { + if (array.getJSONObject(i).getString("to").equals(fromShapeId)) { + tempFromObj = array.getJSONObject(i); + } + } + return getDeptName(array, tempFromObj, elements); + } + } + + public void getAwsOrgCommentContent(JSONObject dataMap, RoleModel role) { + dataMap.put(OutputWordUtil.POSITION, role.getName().replace("\n", "")); //岗位名称// 岗位名称 + //TODO 所属部门/公司 + dataMap.put(OutputWordUtil.COMPANY, "公司"); // 所属公司 + dataMap.put(OutputWordUtil.DEPARTMENT, "部门"); //所属部门 + // 所属部门(当前角色的所有人包括兼职的所属部门) + List tempList = new ArrayList<>(); + Set set = new HashSet<>(); + List list = UserCache.getActiveList(); + // 主角色 + for (UserModel user : list) { + if (role.getId().equals(user.getRoleId())) { + DepartmentModel model = SDK.getORGAPI().getDepartmentById(user.getDepartmentId()); + if (model == null) continue; + tempList.add(model); + set.add(model.getId()); + } + } + // 兼职所属部门 + List mapModels = UserMapCache.getMapListOfRole(role.getId()); + for (UserMapModel userMapModel : mapModels) { + if (userMapModel != null && !set.contains(userMapModel.getDepartmentId())) { + DepartmentModel model = SDK.getORGAPI().getDepartmentById(userMapModel.getDepartmentId()); + tempList.add(model); + } + } + StringBuilder sb = new StringBuilder(); + for (DepartmentModel model : tempList) { + sb.append(model.getName().replace("\n", "")).append(","); + } + String departments = ""; + if (sb.length() > 0) { + departments = sb.substring(0, sb.length() - 1); + } + dataMap.put("role_department", departments);// 所属部门 + + //创建日期 + Timestamp nowTime = new Timestamp(System.currentTimeMillis()); + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + dataMap.put(OutputWordUtil.GENERATEDATE, sdf.format(nowTime)); + //岗位职责 + dataMap.put(OutputWordUtil.ORGDUTIE, ""); + } + +}