diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dao/PublisherClientDao.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dao/PublisherClientDao.java new file mode 100644 index 00000000..e16c1f47 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dao/PublisherClientDao.java @@ -0,0 +1,340 @@ +package com.actionsoft.apps.coe.pal.publisher.client.dao; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.impl.PALRepositoryModelImpl; +import com.actionsoft.apps.coe.pal.publisher.constant.PublisherConstant; +import com.actionsoft.apps.coe.pal.system.util.StringUtil; +import com.actionsoft.bpms.commons.database.RowMapper; +import com.actionsoft.bpms.server.conf.server.AWSServerConf; +import com.actionsoft.bpms.util.DBSql; +public class PublisherClientDao { + + /** + * 获取模型关联的模型Id + * + * @param id + * @return + * @author zhangming + */ + public List> getFileIdsByRelationFileId(String id) { + String sql = "SELECT DISTINCT(r.FILEID), pal.PLNAME, MODIFYDATE FROM APP_ACT_COE_PAL_SHAPE_RLAT r, APP_ACT_COE_PAL_REPOSITORY pal WHERE r.RELATIONFILEID in (" + id + ") AND r.FILEID = pal.ID AND pal.PLCATEGORY='process' ORDER BY MODIFYDATE DESC"; + List> list = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + map.put("id", rs.getString(1)); + map.put("name", rs.getString(2)); + return map; + } + }); + return list; + } + + /** + * 获取模型关联的模型Id(只有文件属性关联) + * + * @param id + * @return + * @author zhangming + */ + public List> getFileIdsByRelationFileId1(String id) { + String sql = "SELECT DISTINCT(r.FILEID), pal.PLNAME, MODIFYDATE FROM APP_ACT_COE_PAL_SHAPE_RLAT r, APP_ACT_COE_PAL_REPOSITORY pal WHERE r.RELATIONFILEID in (" + id + ") AND r.FILEID = pal.ID AND r.SHAPEID='' AND pal.PLCATEGORY='process' ORDER BY MODIFYDATE DESC"; + List> list = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + map.put("id", rs.getString(1)); + map.put("name", rs.getString(2)); + return map; + } + }); + return list; + } + + /** + * 获取管理标准、技术标准和工作标准的Id + * + * @return + * @author zhangming + */ + public Map getControlPolicyId(String wsId) { + Map resultMap = new HashMap(); + String sql = "SELECT ID, PLNAME FROM APP_ACT_COE_PAL_REPOSITORY WHERE PLNAME IN (?,?,?) AND WSID=? AND PLMETHODID='control.policy'"; + List> listMap = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + map.put(rs.getString(2), rs.getString(1)); + return map; + } + }, new Object[]{PublisherConstant.ORG_RELATION_MANAGEMENT_STANDARD, PublisherConstant.ORG_RELATION_TECHNICAL_STANDARD, PublisherConstant.ORG_RELATION_WORK_STANDARD, wsId}); + for (Map map : listMap) { + Set set = map.keySet(); + for (String key : set) { + resultMap.put(key, map.get(key)); + } + } + return resultMap; + } + + + /** + * 获取某个范围内的关联模型Id + * + * @param relationFileIds + * @return + * @author zhangming + */ + public List> getFileIdsByRelation(String relationFileIds) { + if (relationFileIds == null || "".equals(relationFileIds)) { + return new ArrayList>(); + } + String sql = "SELECT pal.ID, pal.PLNAME, p.PUBLISHDATE FROM APP_ACT_COE_PAL_REPOSITORY pal, (" + + " SELECT r.FILEID, MAX(p.PUBLISHDATE) PUBLISHDATE" + + " FROM APP_ACT_COE_PAL_SHAPE_RLAT r, APP_ACT_COE_PAL_PUBLISH p, APP_ACT_COE_PAL_PUBLISH_LIST pl" + + " WHERE r.FILEID = pl.PALREPOSITORYID AND r.RELATIONFILEID IN (" + relationFileIds + ") AND p.ID=pl.PID AND pl.ACTIONTYPE='N'" + + " GROUP BY r.FILEID) p" + + " WHERE pal.ID = p.FILEID and pal.ISPUBLISH=1" + + " ORDER BY p.PUBLISHDATE DESC"; + List> list = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + if (rs.getString(1) == null) { + return null; + } + map.put("id", rs.getString(1)); + map.put("name", rs.getString(2)); + Timestamp publishDate = rs.getTimestamp(3); + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + map.put("publishDate", sdf.format(publishDate)); + return map; + } + }); + return list; + } + + /** + * 获取某个范围内的关联模型Id(只有文件属性关联) + * + * @param relationFileIds + * @return + * @author zhangming + */ + public List> getFileIdsByRelation1(String relationFileIds) { + if (relationFileIds == null || "".equals(relationFileIds)) { + return new ArrayList>(); + } + String sql = "SELECT pal.ID, pal.PLNAME, p.PUBLISHDATE FROM APP_ACT_COE_PAL_REPOSITORY pal, (" + + " SELECT r.FILEID, MAX(p.PUBLISHDATE) PUBLISHDATE" + + " FROM APP_ACT_COE_PAL_SHAPE_RLAT r, APP_ACT_COE_PAL_PUBLISH p, APP_ACT_COE_PAL_PUBLISH_LIST pl" + + " WHERE r.FILEID = pl.PALREPOSITORYID AND r.RELATIONFILEID IN (" + relationFileIds + ") AND r.SHAPEID='' AND p.ID=pl.PID AND pl.ACTIONTYPE='N'" + + " GROUP BY r.FILEID) p" + + " WHERE pal.ID = p.FILEID and pal.ISPUBLISH=1" + + " ORDER BY p.PUBLISHDATE DESC"; + List> list = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + if (rs.getString(1) == null) { + return null; + } + map.put("id", rs.getString(1)); + map.put("name", rs.getString(2)); + Timestamp publishDate = rs.getTimestamp(3); + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + map.put("publishDate", sdf.format(publishDate)); + return map; + } + }); + return list; + } + + /** + * 获取某个范围内的被关联模型Id + * + * @param fileIds + * @param relationFileIds + * @return + * @author zhangming + */ + public List> getRelationFileIds(String fileIds, String relationFileIds) { + if (fileIds == null || "".equals(fileIds) || relationFileIds == null || "".equals(relationFileIds)) { + return new ArrayList>(); + } + String sql = "SELECT pal.ID, pal.PLNAME, p.PUBLISHDATE from APP_ACT_COE_PAL_REPOSITORY pal, (" + + " SELECT r.RELATIONFILEID, MAX(p.PUBLISHDATE) PUBLISHDATE" + + " FROM APP_ACT_COE_PAL_SHAPE_RLAT r, APP_ACT_COE_PAL_PUBLISH p, APP_ACT_COE_PAL_PUBLISH_LIST pl" + + " WHERE r.RELATIONFILEID = pl.PALREPOSITORYID AND r.FILEID IN (" + fileIds + ") AND r.RELATIONFILEID IN (" + relationFileIds + ") AND p.ID=pl.PID AND pl.ACTIONTYPE='N'" + + " GROUP BY r.RELATIONFILEID) p" + + " WHERE pal.ID=p.RELATIONFILEID and pal.ISPUBLISH=1" + + " ORDER BY p.PUBLISHDATE DESC"; + List> list = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + if (rs.getString(1) == null) { + return null; + } + map.put("id", rs.getString(1)); + map.put("name", rs.getString(2)); + Timestamp publishDate = rs.getTimestamp(3); + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + map.put("publishDate", sdf.format(publishDate)); + return map; + } + }); + return list; + } + + /** + * 发布历史 + * + * @param ids + * @return + * @author zhangming + */ + public List> getPublishListData(String ids, String category, String wsId, String methodId) { + if (ids == null || "".equals(ids)) { + return new ArrayList>(); + } + String sql = "SELECT r.ID, r.PLNAME, p.PUBLISHDATE from APP_ACT_COE_PAL_REPOSITORY r, (" + + " SELECT pl.PALREPOSITORYID, MAX(p.PUBLISHDATE) publishdate " + + " FROM APP_ACT_COE_PAL_PUBLISH p, APP_ACT_COE_PAL_PUBLISH_LIST pl" + + " WHERE p.ID=pl.PID AND pl.PALREPOSITORYID IN (" + ids + ")" + + " GROUP BY pl.PALREPOSITORYID ) p" + + " WHERE r.ID = p.PALREPOSITORYID AND r.PLCATEGORY='" + category + "' AND r.PLMETHODID <> 'default' AND r.WSID='" + wsId + "'"; + if (methodId != null && !"".equals(methodId)) { + sql += " AND r.PLMETHODID='" + methodId + "'"; + } + sql += " ORDER BY p.PUBLISHDATE DESC"; + List> list = DBSql.query(sql, new RowMapper>() { + @Override + public Map mapRow(ResultSet rs, int arg1) throws SQLException { + Map map = new HashMap(); + if (rs.getString(1) == null) { + return null; + } + map.put("id", rs.getString(1)); + map.put("name", rs.getString(2)); + Timestamp publishDate = rs.getTimestamp(3); + DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + map.put("publishDate", sdf.format(publishDate)); + return map; + } + }); + return list; + } + /** + * 根据name获取未发布的流程文件 + * @param name + * @param wsId + * @param methodId + * @return + */ + public List getCoeProcessLevelByNamen(String name, String wsId, String methodId) { + String namelike = ""; + if (StringUtil.containSpecialChar(name)) { + namelike = "'%" + StringUtil.replaceSqlStr(name, AWSServerConf.isMySQL()) + "%'" + (AWSServerConf.isMySQL() ? "ESCAPE '\\\\'" : " ESCAPE '\\'"); + } else { + namelike = "'%" + name + "%'"; + } + StringBuilder sql = new StringBuilder("select * from " + PALRepositoryModelImpl.DATABASE_ENTITY + " where " + PALRepositoryModelImpl.FIELD_WS_ID + "='" + wsId + "' and " + PALRepositoryModelImpl.FIELD_PL_NAME + " like " + namelike + " and ISPUBLISH = '0'"); + if (methodId != null && !"".equals(methodId)) { + sql.append(" and PLMETHODID = '" + methodId + "' "); + } + sql.append(" ORDER BY " + PALRepositoryModelImpl.FIELD_PL_ORDERINDEX + " ASC"); + return DBSql.query(sql.toString(), new PALRespositoryModelMapper()); + } + /** + * 根据name获取有多个版本的流程文件 + * @param name + * @param wsId + * @param methodId + * @return + */ + public List getCoeProcessLevelByNamec(String name, String wsId, String methodId) { + String namelike = ""; + if (StringUtil.containSpecialChar(name)) { + namelike = "'%" + StringUtil.replaceSqlStr(name, AWSServerConf.isMySQL()) + "%'" + (AWSServerConf.isMySQL() ? "ESCAPE '\\\\'" : " ESCAPE '\\'"); + } else { + namelike = "'%" + name + "%'"; + } + StringBuilder sql = new StringBuilder("select * from " + PALRepositoryModelImpl.DATABASE_ENTITY + " where " + PALRepositoryModelImpl.FIELD_WS_ID + "='" + wsId + "' and " + PALRepositoryModelImpl.FIELD_PL_NAME + " like " + namelike + " and ISPUBLISH = '1'"); + String sqlcount = "select count(*) from " + PALRepositoryModelImpl.DATABASE_ENTITY + " where " + PALRepositoryModelImpl.FIELD_WS_ID + "='" + wsId + "' and " + PALRepositoryModelImpl.FIELD_PL_NAME + " like " + namelike + ""; + + if (methodId != null && !"".equals(methodId)) { + sql.append(" and PLMETHODID = '" + methodId + "' "); + } + sql.append(" ORDER BY " + PALRepositoryModelImpl.FIELD_PL_ORDERINDEX + " ASC"); + sqlcount+=" ORDER BY " + PALRepositoryModelImpl.FIELD_PL_ORDERINDEX + " ASC"; + String num = DBSql.getString(sqlcount); + int number = Integer.parseInt(num); + if(number <= 1) { + List data = null; + return data; + } + return DBSql.query(sql.toString(), new PALRespositoryModelMapper()); + } + /** + * 根据name获取停用的流程文件 + * @param name + * @param wsId + * @param category + * @return + */ + public List getCoeProcessLevelByNameAndCategorys(String name, String wsId, String category) { + + String namelike = ""; + + if (StringUtil.containSpecialChar(name)) { + namelike = "'%" + StringUtil.replaceSqlStr(name, AWSServerConf.isMySQL()) + "%'" + (AWSServerConf.isMySQL() ? "ESCAPE '\\\\'" : " ESCAPE '\\'"); + } else { + namelike = "'%" + name + "%'"; + } + StringBuilder sql = new StringBuilder("select * from " + PALRepositoryModelImpl.DATABASE_ENTITY + " where " + PALRepositoryModelImpl.FIELD_WS_ID + "='" + wsId + "' and " + PALRepositoryModelImpl.FIELD_PL_NAME + " like " + namelike + " and " + PALRepositoryModelImpl.FIELD_IS_USE + "='1' and ISPUBLISH = '1'"); + + if (category != null && !"".equals(category)) { + sql.append(" and PLCATEGORY = '" + category + "' "); + } + sql.append(" ORDER BY " + PALRepositoryModelImpl.FIELD_PL_ORDERINDEX + " ASC"); + return DBSql.query(sql.toString(), new PALRespositoryModelMapper()); + } + private class PALRespositoryModelMapper implements RowMapper { + PALRepository pal = new PALRepository(); + public PALRepositoryModel mapRow(ResultSet rs, int arg1) throws SQLException { + return (PALRepositoryModel) pal.record2Model(rs); + } + } + /** + * 根据userId获取资源Id列表 + * @param userId + * @return + */ + public List getTeamUserPerms(String userId) { + String sql = " select distinct perm.RESOURCEID from APP_ACT_NETWORK_TEAM_MEMBER tm , APP_ACT_COE_TEAM_PERM perm " + + "where tm.TEAMID=perm.TEAMID and tm.MEMBERSTATUS='1' and tm.USERID=? "; + List resourceIdList = DBSql.query(sql.toString(), new RowMapper() { + @Override + public String mapRow(ResultSet rs, int arg1) throws SQLException { + return rs.getString(1); + } + }, new Object[] { userId }); + if(resourceIdList == null) { + resourceIdList = new ArrayList(); + } + return resourceIdList; + } + +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dto/ProcessPublishDTO.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dto/ProcessPublishDTO.java new file mode 100644 index 00000000..d61210f6 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dto/ProcessPublishDTO.java @@ -0,0 +1,106 @@ +package com.actionsoft.apps.coe.pal.publisher.client.dto; + +/** + * 流程发布代办已办传输类 + * + * @author 郝文豪(James) + * @date 2020/7/13 0013 上午 11:16 + */ +public class ProcessPublishDTO { + /** + * 流程实例id + */ + private String processInstId; + /** + * 序号 + */ + private int index; + /** + * 标题 + */ + private String title; + /** + * 来自谁+部门 + */ + private String fromUser; + /** + * 接收时间 + */ + private String date; + /** + * 是否是自己发起填写的流程 + */ + private boolean ownerProcess; + /** + * 任务实例id + */ + private String taskInstId; + /** + * 打开状态 + */ + private String openState; + + public String getProcessInstId() { + return processInstId; + } + + public void setProcessInstId(String processInstId) { + this.processInstId = processInstId; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getFromUser() { + return fromUser; + } + + public void setFromUser(String fromUser) { + this.fromUser = fromUser; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public boolean isOwnerProcess() { + return ownerProcess; + } + + public void setOwnerProcess(boolean ownerProcess) { + this.ownerProcess = ownerProcess; + } + + public String getTaskInstId() { + return taskInstId; + } + + public void setTaskInstId(String taskInstId) { + this.taskInstId = taskInstId; + } + + public String getOpenState() { + return openState; + } + + public void setOpenState(String openState) { + this.openState = openState; + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dto/ProcessPublishHistoryDTO.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dto/ProcessPublishHistoryDTO.java new file mode 100644 index 00000000..39f4c1e4 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/dto/ProcessPublishHistoryDTO.java @@ -0,0 +1,140 @@ +package com.actionsoft.apps.coe.pal.publisher.client.dto; + +import java.io.Serializable; + +/** + * 流程发布的数据传输对象类 + * + * @author 郝文豪(James) + * @date 2020/4/7 0007 下午 2:09 + */ +public class ProcessPublishHistoryDTO implements Serializable { + /** + * 流程实例id + */ + private String processInstId; + /** + * 标题 + */ + private String title; + + /** + * 申请人 + */ + private String createUser; + + /** + * 申请时间 + */ + private String createTime; + + /** + * 类型 + */ + private String type; + + /** + * 审批状态 + */ + private String approvalState; + + /** + * 审批人 + */ + private String approvalUser; + + /** + * 审批人id + */ + private String approvalUserId; + + /** + * 是否完成 + */ + private Boolean end; + + /** + * 任务实例id + */ + private String taskInstId; + + public String getTaskInstId() { + return taskInstId; + } + + public void setTaskInstId(String taskInstId) { + this.taskInstId = taskInstId; + } + + public String getProcessInstId() { + return processInstId; + } + + public void setProcessInstId(String processInstId) { + this.processInstId = processInstId; + } + + public Boolean getEnd() { + return end; + } + + public void setEnd(Boolean end) { + this.end = end; + } + + public String getApprovalUserId() { + return approvalUserId; + } + + public void setApprovalUserId(String approvalUserId) { + this.approvalUserId = approvalUserId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getCreateUser() { + return createUser; + } + + public void setCreateUser(String createUser) { + this.createUser = createUser; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getApprovalState() { + return approvalState; + } + + public void setApprovalState(String approvalState) { + this.approvalState = approvalState; + } + + public String getApprovalUser() { + return approvalUser; + } + + public void setApprovalUser(String approvalUser) { + this.approvalUser = approvalUser; + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/util/PublisherSkinsDao.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/util/PublisherSkinsDao.java new file mode 100644 index 00000000..d3e975c0 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/util/PublisherSkinsDao.java @@ -0,0 +1,32 @@ +package com.actionsoft.apps.coe.pal.publisher.client.util; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import com.actionsoft.bpms.commons.database.RowMapper; +import com.actionsoft.bpms.commons.pagination.SQLPagination; +import com.actionsoft.bpms.util.DBSql; + +/** + * 导航处理类 + * + * @author ZZ + * + */ +public class PublisherSkinsDao { + + public long getPrevLoginTime(String userId) { + long prevLoginTime = 0; + String sql = " select * from SYS_SESSION s where s.userid = '" + userId + "' order by s.STARTTIME desc "; + List list = DBSql.query(SQLPagination.getPaginitionSQL(sql, 0, 2), new RowMapper() { + public Long mapRow(ResultSet rs, int paramInt) throws SQLException { + return rs.getLong("starttime"); + } + }); + if (list != null && list.size() > 0) { + prevLoginTime = list.get(list.size() - 1); + } + return prevLoginTime; + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/web/ProcessPublishClientWeb.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/web/ProcessPublishClientWeb.java new file mode 100644 index 00000000..d1b97c52 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/client/web/ProcessPublishClientWeb.java @@ -0,0 +1,4791 @@ +package com.actionsoft.apps.coe.pal.publisher.client.web; + +import java.io.File; +import java.sql.Timestamp; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI; +import com.actionsoft.apps.coe.pal.log.CoEOpLogConst; +import com.actionsoft.apps.coe.pal.pal.manage.publish.constant.PublishConst; + +import com.actionsoft.apps.AppsConst; +import com.actionsoft.apps.coe.pal.pal.ws.web.VersionUtil; +import com.actionsoft.apps.coe.pal.publisher.client.dao.PublisherClientDao; +import com.actionsoft.apps.coe.pal.publisher.conf.PublisherConf; +import com.actionsoft.apps.coe.pal.publisher.constant.PublisherConstant; +import com.actionsoft.apps.coe.pal.team.user.web.UserWeb; +import com.actionsoft.apps.coe.pal.util.HighSecurityUtil; +import com.actionsoft.apps.lifecycle.api.AppsAPIManager; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile; +import com.actionsoft.bpms.bpmn.modeler.io.BPMNIO; +import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.commons.portal.pub.web.PublicPortalWeb; +import com.actionsoft.bpms.commons.portal.skins.AbstPortalSkins; +import com.actionsoft.bpms.commons.portal.skins.PortalSkinsInterface; +import com.actionsoft.bpms.org.cache.UserCache; +import com.actionsoft.bpms.org.cache.UserMapCache; +import com.actionsoft.bpms.org.model.CompanyModel; +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.bpms.server.UserContext; +import com.actionsoft.bpms.server.fs.DCContext; +import com.actionsoft.bpms.server.fs.dc.DCProfileManager; +import com.actionsoft.bpms.util.Base64; +import com.actionsoft.bpms.util.UtilDate; +import com.actionsoft.bpms.util.UtilFile; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.pal.manage.publish.cache.PublishHistoryCache; +import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishCommonDao; +import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishFrequencyDao; +import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishListHistory; +import com.actionsoft.apps.coe.pal.pal.manage.publish.model.PublishFrequencyModel; +import com.actionsoft.apps.coe.pal.pal.manage.publish.model.PublishHistoryModel; +import com.actionsoft.apps.coe.pal.pal.manage.publish.model.PublishListHistoryModel; +import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache; +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.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository; +import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache; +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.apps.coe.pal.pal.repository.model.impl.PALRepositoryModelImpl; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.constant.CoeFileConstant; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.dao.UpFileDao; +import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel; +import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; +import com.actionsoft.apps.coe.pal.pal.ws.dao.CoeWorkSpace; +import com.actionsoft.apps.coe.pal.pal.ws.dao.CoeWorkSpaceDaoFactory; +import com.actionsoft.apps.coe.pal.pal.ws.model.CoeWorkSpaceModel; +import com.actionsoft.apps.coe.pal.team.user.dao.CoeUser; +import com.actionsoft.apps.coe.pal.team.user.dao.CoeUserDaoFactory; +import com.actionsoft.exception.AWSException; +import com.actionsoft.i18n.I18nRes; +import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections4.IteratorUtils; + +public class ProcessPublishClientWeb extends AbstPortalSkins implements PortalSkinsInterface { + private UserContext _uc; + + public ProcessPublishClientWeb() { + } + + public ProcessPublishClientWeb(UserContext userContext) { + _uc = userContext; + } + + @Override + public String getHomePage(UserContext uc) { + _uc = uc; + // 操作行为日志记录 + if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) { + CoEOpLogAPI.auditOkOp(uc, CoEOpLogConst.MODULE_CATEGORY_APPCENTER, CoEOpLogConst.OP_ACCESS, CoEOpLogConst.INFO_APPCENTER_ACCESS_PREFIX + SDK.getAppAPI().getAppContext(PublisherConf.APPID).getName() + CoEOpLogConst.INFO_APPCENTER_ACCESS_SUFFIX); + } + if (PublisherConf.PUBLISH_PORTAL_VERSION.equals("v3")) { + Map macroLibraries = getHomePage2(uc); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.home2.html", macroLibraries); + } else { + AppAPI appApi = SDK.getAppAPI(); + JSONArray wsTree = new JSONArray(); + String isIntegrationAWSUser = appApi.getProperty(PublisherConstant.PUBLISH, "isIntegrationAWSUser"); //是否整合AWS用户 + String roleId = ""; + if ("false".equals(isIntegrationAWSUser)) { + roleId = PublishConst.GUESTROLE; + } else { + roleId = uc.getRoleModel().getId(); + } + String emptyMessage = ""; + PALRepository dao = new PALRepository(); + List> allWsList = dao.getWorkSpaceListByPublishRole(roleId, false); + if (allWsList == null || allWsList.size() == 0) { + emptyMessage = "未分配资产库访问权限"; + } + List> wsList = dao.getWorkSpaceListByPublishRole(roleId, true); // 有访问权限的资产库 + StringBuilder wsIds = new StringBuilder(""); + StringBuilder modelIds = new StringBuilder(""); + JSONArray repositoryList = new JSONArray(); // 有访问权限的文件 + if (wsList != null && wsList.size() > 0) { + int i = 0; + List> removeList = new ArrayList>(); + for (Map ws : wsList) { + boolean isActive = PALRepositoryQueryAPIManager.getInstance().isActiveWorkSpace(ws.get("wsId")); + if (!isActive) { + removeList.add(ws); + } else { + JSONObject wsJson = new JSONObject(); + wsJson.put("id", ws.get("wsId")); + wsJson.put("name", ws.get("wsName")); + if (i == 0) { + wsJson.put("open", true); + } else { + wsJson.put("open", false); + } + wsJson.put("ws", true); + wsJson.put("wsName", ws.get("wsName")); + if (PublisherConf.PUBLISH_PORTAL_VERSION.equals("v1")) { + wsJson.put("icon", PublisherConf.PORTAL_TREE_ICON_FOLDER); + } else { + wsJson.put("icon", PublisherConf.PORTAL_TREE_ICON_FOLDER1); + } + wsTree.add(wsJson); + wsIds.append(ws.get("wsId")).append(","); + i++; + } + } + wsList.removeAll(removeList); + + if (wsList.size() > 0) { + ProcessPublishWeb web = new ProcessPublishWeb(uc); + for (Map ws : wsList) { + List repositoryModelList = dao.getRepositoryListByPublishRole(roleId, ws.get("wsId")); + repositoryList.addAll(web.getRepositoryTree(repositoryModelList, ws.get("wsId"), true, false, false, null, false)); + } + } else { + emptyMessage = "资产库被停用"; + } + } else { + emptyMessage = "可访问流程未发布"; + } + + if (repositoryList != null && repositoryList.size() > 0) { + wsTree.addAll(repositoryList); + for (int i = 0; i < repositoryList.size(); i++) { + String versionId = ""; + if (repositoryList.getJSONObject(i).containsKey("versionId")) { + versionId = repositoryList.getJSONObject(i).getString("versionId"); + } else { + versionId = repositoryList.getJSONObject(i).getString("id"); + } + modelIds.append(versionId).append(","); + } + } + + boolean isComment = PublisherConf.isComment(); //允许留言 + boolean isViewHistory = PublisherConf.isViewHistory(); //允许查看历史发布记录 + boolean isViewAttribute = PublisherConf.isViewAttribute(); //允许查看属性 + boolean isPrint = PublisherConf.isPrint(); //允许打印 + String fotter = PublisherConf.getFotter(); //页底信息 + fotter = fotter == null ? "" : fotter; + String title = PublisherConf.getTitle(); //门户标题 + JSONObject dockDisplay = new JSONObject(); + if (!isComment) { + dockDisplay.put("messageView", "display: none;"); + } + if (!isViewHistory) { + dockDisplay.put("publishView", "display: none;"); + } + if (!isViewAttribute) { + dockDisplay.put("attributeView", "display: none;"); + } + if (!isPrint) { + dockDisplay.put("printView", "display: none;"); + } + Map macroLibraries = new HashMap(); + boolean isCoEUser = CoeUserDaoFactory.createUser().validateIsAccessCOE(uc.getUID()); + //公共方法 判断密码修改周期 + PublicPortalWeb portalWeb = new PublicPortalWeb(uc); + JSONObject params = portalWeb.getLoginCheckSecurityInfo(); + macroLibraries.put("isSecurityPwdChange", params.getBoolean("isSecurityPwdChange")); + macroLibraries.put("forceChangePwd", params.getBoolean("forceChangePwd")); + macroLibraries.put("isSecurityPwdComplexity", params.getBoolean("isSecurityPwdComplexity")); + macroLibraries.put("securityMinPwdLength", params.getIntValue("securityMinPwdLength")); + macroLibraries.put("securityMaxPwdLength", params.getIntValue("securityMaxPwdLength")); + macroLibraries.put("sid", uc.getSessionId()); + macroLibraries.put("roleId", roleId); + macroLibraries.put("wsTree", wsTree); + macroLibraries.put("wsId", (wsList == null || wsList.size() == 0) ? "" : wsList.get(0).get("wsId")); + macroLibraries.put("wsName", (wsList == null || wsList.size() == 0) ? "" : wsList.get(0).get("wsName")); + macroLibraries.put("dockDisplay", dockDisplay.toString()); + macroLibraries.put("fotter", fotter.length() > 40 ? fotter.substring(0, 39) : fotter); + macroLibraries.put("title", title.length() > 20 ? title.substring(0, 19) : title); + macroLibraries.put("isComment", isComment); + macroLibraries.put("isViewHistory", isViewHistory); + macroLibraries.put("isViewAttribute", isViewAttribute); + macroLibraries.put("isPrint", isPrint); + macroLibraries.put("userName", uc.getUserName()); + macroLibraries.put("userPhoto", SDK.getPortalAPI().getUserPhoto(uc, uc.getUID())); + macroLibraries.put("emptyMessage", emptyMessage); + macroLibraries.put("entryCoEView", isCoEUser && HighSecurityUtil.allow3PLoginPal(uc.getUID()) ? "" : "display: none;"); + macroLibraries.put("settingView", uc.getUID().equals("admin") ? "" : "display: none;"); + macroLibraries.put("appId", PublisherConf.APPID); + String wsIdsStr = wsIds.toString(); + macroLibraries.put("wsIds", wsIdsStr.contains(",") ? wsIdsStr.substring(0, wsIdsStr.lastIndexOf(",")) : wsIdsStr); + String modelIdsStr = modelIds.toString(); + macroLibraries.put("modelIds", modelIdsStr.contains(",") ? modelIdsStr.substring(0, modelIdsStr.lastIndexOf(",")) : modelIdsStr); + //App-关联查询 + AppContext relationSearchAppContext = AppsAPIManager.getInstance().getAppContext(PublisherConf.RELATION_SEARCH_ID); + macroLibraries.put("relationSearchId", PublisherConf.RELATION_SEARCH_ID.replace(".", "_")); + macroLibraries.put("relationSearchTitle", PublisherConf.RELATION_SEARCH_NAME); + macroLibraries.put("relationSearchCmd", "_portal_home"); + if (relationSearchAppContext != null && SDK.getAppAPI().isActive(relationSearchAppContext.getId())) { + macroLibraries.put("relationSearchIcon", relationSearchAppContext.getIcon16Url(uc)); + macroLibraries.put("relationSearchName", relationSearchAppContext.getName()); + macroLibraries.put("showRelationSearch", ""); + } else { + macroLibraries.put("showRelationSearch", "display: none;"); + } + if (PublisherConf.PUBLISH_PORTAL_VERSION.equals("v1")) { + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.home.html", macroLibraries); + } else if (PublisherConf.PUBLISH_PORTAL_VERSION.equals("v2")) { + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.home1.html", macroLibraries); + } + return null; + } + } + + /** + * v3新版门户 + * @return + */ + public Map getHomePage2(UserContext uc) { + Map macroLibraries = new HashMap(); + AppAPI appApi = SDK.getAppAPI(); + JSONArray wsTree = new JSONArray(); + String isIntegrationAWSUser = appApi.getProperty(PublisherConstant.PUBLISH, "isIntegrationAWSUser"); //是否整合AWS用户 + String roleId = ""; + if ("false".equals(isIntegrationAWSUser)) { + roleId = PublishConst.GUESTROLE; + } else { + roleId = uc.getRoleModel().getId(); + } + boolean isCoEUser = CoeUserDaoFactory.createUser().validateIsAccessCOE(uc.getUID()); + //公共方法 判断密码修改周期 + PublicPortalWeb portalWeb = new PublicPortalWeb(uc); + JSONObject params = portalWeb.getLoginCheckSecurityInfo(); + macroLibraries.put("isSecurityPwdChange", params.getBoolean("isSecurityPwdChange")); + macroLibraries.put("forceChangePwd", params.getBoolean("forceChangePwd")); + macroLibraries.put("isSecurityPwdComplexity", params.getBoolean("isSecurityPwdComplexity")); + macroLibraries.put("securityMinPwdLength", params.getIntValue("securityMinPwdLength")); + macroLibraries.put("securityMaxPwdLength", params.getIntValue("securityMaxPwdLength")); + macroLibraries.put("sid", uc.getSessionId()); + macroLibraries.put("roleId", roleId); + macroLibraries.put("wsTree", wsTree); + macroLibraries.put("userName", uc.getUserName()); + macroLibraries.put("userPhoto", SDK.getPortalAPI().getUserPhoto(uc, uc.getUID())); + macroLibraries.put("entryCoEView", isCoEUser && HighSecurityUtil.allow3PLoginPal(uc.getUID()) ? "" : "display: none;"); + macroLibraries.put("settingView", uc.getUID().equals("admin") ? "" : "display: none;"); + macroLibraries.put("appId", PublisherConf.APPID); + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, null); + JSONArray ws = new JSONArray(); + if (wsList != null && wsList.size() > 0) { + for (int i = 0; i < wsList.size(); i++) { + JSONObject object = new JSONObject(); + object.put("id", wsList.get(i).get("wsId")); + object.put("text", wsList.get(i).get("wsName")); + object.put("initDisplay", "0"); + ws.add(object); + } + } + macroLibraries.put("ws", ws); + macroLibraries.put("palAdmin", new CoeUser().isCoEManager(uc.getUID())); + // 获取logo图片路径 + JSONObject object = getLogoImgPath(uc); + macroLibraries.put("logoImgPath", object.getString("src")); + macroLibraries.put("logoImgName", object.getString("name")); + // 门户参数 + macroLibraries.put("xpagesId", PublisherConf.XPAGES_ID); + macroLibraries.put("portalTabs", PublisherConf.PORTAL_TABS); + return macroLibraries; + } + + /** + * 首页 + * + * @return + * @author zhangming + */ + public String getClientMain(String wsId) { + JSONArray result = search("", null, null, null); //所有文件 + + JSONArray plrdArray = new JSONArray(); + JSONArray plrpArray = new JSONArray(); + PALRepository dao = new PALRepository(); + List> plrds = dao.searchRepositoryPlrdByPublisherPortal(_uc.getRoleModel().getId()); + for (Map plrd : plrds) { + if (plrd != null && plrd.containsKey("id") && !plrd.get("id").equals("")) { + plrdArray.add(plrd); + } + } + List> plrps = dao.searchRepositoryPlrpByPublisherPortal(_uc.getRoleModel().getId()); + for (Map plrp : plrps) { + if (plrp != null && plrp.containsKey("id") && !plrp.get("id").equals("")) { + plrpArray.add(plrp); + } + } + + Map macroLibraries = new HashMap(); + macroLibraries.put("result", result); + macroLibraries.put("plrd", plrdArray); + macroLibraries.put("plrp", plrpArray); + macroLibraries.put("wsId", wsId); + macroLibraries.put("sid", _uc.getSessionId()); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.main.html", macroLibraries); + } + + /** + * 查询 + * + * @param modelIds + * @param filter + * @param order + * @param name + * @return + * @author zhangming + */ + public String searchInClientMain(String modelIds, String filter, String order, String name) { + JSONArray result = search(modelIds, filter, order, name); + + ResponseObject ro = ResponseObject.newOkResponse(); + ro.put("result", result); + return ro.toString(); + } + + private JSONArray search(String modelIds, String filter, String order, String name) { + PALRepository dao = new PALRepository(); + List models = dao.searchRepositoryByPublisherPortal(modelIds, filter, order, name); + + List jsonList = new ArrayList<>(); + for (String id : models) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model == null) { + continue; + } + + boolean isActive = false; + if (model != null && !"default".equals(model.getMethodId())) { + if (PALMethodCache.getPALMethodModelById(model.getMethodId()) == null) { + isActive = false; + } else { + String methodId = PALMethodCache.getPALMethodModelById(model.getMethodId()).getApp().getId(); + isActive = SDK.getAppAPI().isActive(methodId); + } + } + + String processDefId = ""; + String appId = ""; + if (model != null) {// 获取流程版本id + appId = CoeProcessLevelUtil.getAppId(model.getId()); + processDefId = CoeProcessLevelUtil.getProcessDefIdByVer(appId, model.getId(), (int)model.getVersion()); + } + + String p = model.getFilePath(); + String imagePath = "../apps/"+ CoEConstant.APP_ID +"/img/method/default.png"; + if (!processDefId.equals("")) { + imagePath = "data:image/png;base64," + BPMNIO.getBPMNImageThumbnail(CoeProcessLevelUtil.getAppId(model.getId()), processDefId); + } else { + if (!"".equals(p)) { + UtilFile utilFile = new UtilFile(p + "/" + model.getId() + ".small.png"); + if (utilFile.exists()) { + byte[] base64Bytes = Base64.encode(utilFile.readBytes()); + imagePath = "data:image/png;base64," + new String(base64Bytes); + } + } + } + if ("default".equals(model.getMethodId())) { + imagePath = "../apps/com.actionsoft.apps.coe.pal.publisher/img/default_folder.png"; + } + + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("imgPath", imagePath); + object.put("processDefId", processDefId); + object.put("methodId", model.getMethodId()); + String relationType = SDK.getAppAPI().getProperty(CoEConstant.APP_ID, CoEConstant.PROPERTY_RELATION_TYPE); + object.put("plrd", ""); + object.put("plrp", ""); + if ("address".equals(relationType)) { + String dutyDept = model.getDutyDept(); + if (!UtilString.isEmpty(dutyDept)) { + if (SDK.getORGAPI().getDepartmentById(dutyDept) != null) { + dutyDept = SDK.getORGAPI().getDepartmentById(dutyDept).getName(); + object.put("plrd", dutyDept); + } + } + String dutyPerson = model.getDutyUser(); + if (!UtilString.isEmpty(dutyPerson)) { + object.put("plrp", SDK.getORGAPI().getUserAliasNames(dutyPerson)); + } + } else { + String plrdId = model.getOwnerDept(); + if (plrdId != null && !"".equals(plrdId)) { + List list = DesignerShapeRelationCache.getListByAttrId(id, "", "plRD"); + if (list != null && list.size() > 0) { + object.put("plrd", list.get(0).getRelationShapeText()); + } else { + object.put("plrd", ""); + } + } + String plrpId = model.getOwnerUser(); + if (plrpId != null && !"".equals(plrpId)) { + List list = DesignerShapeRelationCache.getListByAttrId(id, "", "plRP"); + if (list != null && list.size() > 0) { + object.put("plrp", list.get(0).getRelationShapeText()); + } else { + object.put("plrp", ""); + } + } + } + object.put("version", model.getVersion()); + object.put("isActive", isActive); + + if (model.isPublish()) { + PublishListHistory historyDao = new PublishListHistory(); + String lastPublishDate = historyDao.getLastPublishDateByModelId(model.getId()); + if (lastPublishDate != null && !"".equals(lastPublishDate)) { + lastPublishDate = lastPublishDate.substring(0, 10); + } + object.put("publishDate", lastPublishDate == null ? "" : lastPublishDate); + } else { + object.put("publishDate", ""); + } + + jsonList.add(object); + } + + if (order != null && order.contains("plrd")) { + Collections.sort(jsonList, new ComparatorPlrdChinese()); + } + if (order != null && order.contains("plrp")) { + Collections.sort(jsonList, new ComparatorPlrpChinese()); + } + return JSONArray.parseArray(JSON.toJSONString(jsonList)); + } + + private class ComparatorPlrdChinese implements Comparator { + @Override + public int compare(JSONObject model1, JSONObject model2) { + String plrd1 = model1.getString("plrd"); + String plrd2 = model2.getString("plrd"); + return Collator.getInstance(Locale.CHINESE).compare(plrd1, plrd2); + } + } + + private class ComparatorPlrpChinese implements Comparator { + @Override + public int compare(JSONObject model1, JSONObject model2) { + String plrp1 = model1.getString("plrp"); + String plrp2 = model2.getString("plrp"); + return Collator.getInstance(Locale.CHINESE).compare(plrp1, plrp2); + } + } + + /** + * 查询发布历史 + * + * @param start + * @param type N/C/S,如果查询全部该字段为空 + * @return + * @author zhangming + */ + public String getPublishList(String start, String type) { + ProcessPublishWeb web = new ProcessPublishWeb(_uc); + JSONArray list = web.getMorePublishHistory(start, "50", type); + + ResponseObject ro = ResponseObject.newOkResponse(); + ro.put("results", list); + return ro.toString(); + } + + public String getSettingData() { + boolean isComment = PublisherConf.isComment(); //允许留言 + boolean isViewHistory = PublisherConf.isViewHistory(); //允许查看历史发布记录 + boolean isViewAttribute = PublisherConf.isViewAttribute(); //允许查看属性 + boolean isPrint = PublisherConf.isPrint(); //允许打印 + String fotter = PublisherConf.getFotter(); //页底信息 + fotter = fotter == null ? "" : fotter; + String title = PublisherConf.getTitle(); //门户标题 + ResponseObject ro = ResponseObject.newOkResponse(); + ro.put("isComment", isComment + ""); + ro.put("isViewHistory", isViewHistory + ""); + ro.put("isViewAttribute", isViewAttribute + ""); + ro.put("isPrint", isPrint + ""); + ro.put("fotter", fotter); + ro.put("title", title); + return ro.toString(); + } + + /** + * 参数设置 + * + * @param title + * @param fotter + * @param isComment + * @param isPrint + * @param isViewAttribute + * @param isViewHistory + * @return + * @author zhangming + */ + public String setting(String title, String fotter, String isComment, String isPrint, String isViewAttribute, String isViewHistory) { + PublisherConf.setTitle(title); + PublisherConf.setFotter(fotter); + PublisherConf.setComment(isComment); + PublisherConf.setPrint(isPrint); + PublisherConf.setViewAttribute(isViewAttribute); + PublisherConf.setViewHistory(isViewHistory); + ResponseObject ro = ResponseObject.newOkResponse(); + return ro.toString(); + } + + /** + * 获取资产库列表 + * + * @return + * @author zhangming + */ + public String getOrgWsTreeData() { + ResponseObject ro = ResponseObject.newOkResponse(); + + List wsList = CoeWorkSpaceDaoFactory.createCoeWorkSpace().getInstanceAll(); + JSONArray wsTree = new JSONArray(); + if (wsList != null && wsList.size() > 0) { + int i = 0; + for (CoeWorkSpaceModel ws : wsList) { + boolean isActive = PALRepositoryQueryAPIManager.getInstance().isActiveWorkSpace(ws.getUUId()); + if (isActive) { + JSONObject wsJson = new JSONObject(); + String wsId = ws.getUUId(); + wsJson.put("id", wsId); + wsJson.put("name", ws.getWsName()); + if (i == 0) { + wsJson.put("open", true); + } else { + wsJson.put("open", false); + } + wsJson.put("ws", true); + wsJson.put("wsId", wsId); + wsJson.put("wsName", ws.getWsName()); + if (PublisherConf.PUBLISH_PORTAL_VERSION.equals("v1")) { + wsJson.put("icon", PublisherConf.PORTAL_TREE_ICON_FOLDER); + } else { + wsJson.put("icon", PublisherConf.PORTAL_TREE_ICON_FOLDER1); + } + wsTree.add(wsJson); + i++; + + JSONArray jsonArray = PALRepositoryQueryAPIManager.getInstance().getPalRepositoryTreeData(_uc, wsId, "org", "isUsed"); + for (int j = 0; j < jsonArray.size(); j++) { + JSONObject object = jsonArray.getJSONObject(j); + if (object.getString("id").equals("org")) { + object.put("id", wsId + "_org"); + object.put("pid", wsId); + object.put("icon", PublisherConf.PORTAL_TREE_ICON_FOLDER1); + } else { + if (object.getString("pid").equals("org")) { + object.put("pid", wsId + "_org"); + } + if (object.getString("isParent") == "true") { + object.put("icon", PublisherConf.PORTAL_TREE_ICON_FOLDER1); + } else { + object.put("icon", ""); + } + } + + wsTree.add(object); + } + } + } + } + ro.put("wsTreeData", wsTree); + return ro.toString(); + } + + /** + * 标准化体系页面 + * + * @return + * @author zhangming + */ + public String toOrgRelationPage() { + Map macroLibraries = new HashMap(); + macroLibraries.put("sid", _uc.getSessionId()); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.org.html", macroLibraries); + } + + /** + * 组织模型相关的模型页面 + * + * @return + * @author zhangming + */ + public String toOrgRelationModelPage() { + Map macroLibraries = new HashMap(); + macroLibraries.put("sid", _uc.getSessionId()); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.org.main.html", macroLibraries); + } + + public String getOrgRelativeModel(String orgModelId, String modelIds) { + ResponseObject ro = ResponseObject.newOkResponse(); + ro.put("data", getOrgRelationModelList(orgModelId, modelIds)); + return ro.toString(); + } + + private JSONObject getOrgRelationModelList(String orgModelId, String modelIds) { + JSONObject data = new JSONObject(); + + //如果orgModelId为空,则查询发布历史 + if (orgModelId == null || "".equals(orgModelId)) { + PublisherClientDao publisherDao = new PublisherClientDao(); + String[] modelIdArray = modelIds.split(","); + StringBuilder sb = new StringBuilder(); + if (modelIdArray.length > 0) { + for (String modelId : modelIdArray) { + if (!"".equals(modelId)) { + sb.append("'" + modelId + "',"); + } + } + } + if (sb.length() > 0) { + String wsId = ""; + if (modelIdArray[0].length() > 36) { + wsId = modelIdArray[0].substring(modelIdArray[0].indexOf("_") + 1); + } else if (modelIdArray[0].length() == 36) { + if (PALRepositoryCache.getCache().get(modelIdArray[0]) != null) { + wsId = PALRepositoryCache.getCache().get(modelIdArray[0]).getWsId(); + } + } else { + return data; + } + + String sqlIds = sb.substring(0, sb.lastIndexOf(",")); + List> processList = publisherDao.getPublishListData(sqlIds, "process", wsId, null); + data.put("processList", processList); + Map controlPolicyIds = publisherDao.getControlPolicyId(wsId); + //管理标准 + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_MANAGEMENT_STANDARD)) { + List> managementRoleList = new ArrayList>(); + List> technicalRoleList = new ArrayList>(); + List> workRoleList = new ArrayList>(); + String publishedManagementStandardIds = ""; + String publishedTechnicalStandardIds = ""; + String publishedWorkStandardIds = ""; + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_MANAGEMENT_STANDARD)) { + String managementStandardId = controlPolicyIds.get(PublisherConstant.ORG_RELATION_MANAGEMENT_STANDARD); + publishedManagementStandardIds = getRelationPublishedControlIds(wsId, managementStandardId, "control.policy"); + } + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_TECHNICAL_STANDARD)) { + String technicalStandardId = controlPolicyIds.get(PublisherConstant.ORG_RELATION_TECHNICAL_STANDARD); + publishedTechnicalStandardIds = getRelationPublishedControlIds(wsId, technicalStandardId, "control.policy"); + } + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_WORK_STANDARD)) { + String workStandardId = controlPolicyIds.get(PublisherConstant.ORG_RELATION_WORK_STANDARD); + publishedWorkStandardIds = getRelationPublishedControlIds(wsId, workStandardId, "control.policy"); + } + + List> list = publisherDao.getPublishListData(sqlIds, "control", wsId, "control.policy"); + if (list != null && list.size() > 0) { + for (Map map : list) { + String id = map.get("id").toString(); + if (publishedManagementStandardIds.contains(id)) { + managementRoleList.add(map); + } else if (publishedTechnicalStandardIds.contains(id)) { + technicalRoleList.add(map); + } else if (publishedWorkStandardIds.contains(id)) { + workRoleList.add(map); + } + + } + } + data.put("managementList", managementRoleList); + data.put("technicalList", technicalRoleList); + data.put("workList", workRoleList); + } else { + data.put("managementList", new ArrayList()); + data.put("technicalList", new ArrayList()); + data.put("workList", new ArrayList()); + } + } + + return data; + } + + PALRepositoryModel orgModel = PALRepositoryCache.getCache().get(orgModelId); + String wsId = orgModel.getWsId(); + if (orgModel != null) { + List orgList = new ArrayList(); + PALRepositoryQueryAPIManager.getInstance().getAllUsedPalRepositoryModelsByPid(wsId, orgModelId, orgList); //组织模型的所有子流程 + StringBuilder sbOrgIds = new StringBuilder("'" + orgModelId + "'"); + if (orgList != null && orgList.size() > 0) { + for (PALRepositoryModel model : orgList) { + sbOrgIds.append(",'").append(model.getId()).append("'"); + } + } + //流程模型 + PublisherClientDao publisherDao = new PublisherClientDao(); + List> processIdList = publisherDao.getFileIdsByRelationFileId1(sbOrgIds.toString()); //org模型关联的流程模型Id + List> processList = publisherDao.getFileIdsByRelation1(sbOrgIds.toString()); + String processIds = ""; //processIds保存org模型关联的所有process模型Id,包括已发布和未发布的 + if (processIdList != null && processIdList.size() > 0) { + StringBuilder sbProcessIds = new StringBuilder(); + for (Map processMap : processIdList) { + String processId = processMap.get("id").toString(); + sbProcessIds.append("'").append(processId).append("',"); + } + processIds = sbProcessIds.substring(0, sbProcessIds.lastIndexOf(",")); + } + data.put("processIds", processIds); + List> processOrgList = new ArrayList>(); + if (processList != null) { + for (Map map : processList) { + if (modelIds.contains(map.get("id").toString())) { + processOrgList.add(map); + } + } + } + data.put("processList", processOrgList); + + //根据流程模型,获取关联的制度模型 + Map controlPolicyIds = publisherDao.getControlPolicyId(wsId); + //管理标准 + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_MANAGEMENT_STANDARD)) { + String managementStandardId = controlPolicyIds.get(PublisherConstant.ORG_RELATION_MANAGEMENT_STANDARD); + String publishedManagementStandardIds = getRelationPublishedControlIds(wsId, managementStandardId, "control.policy"); + List> managementList = publisherDao.getRelationFileIds(processIds, publishedManagementStandardIds); + List> managementRoleList = new ArrayList>(); + if (managementList != null && managementList.size() > 0) { + for (Map managementMap : managementList) { + String id = managementMap.get("id").toString(); + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (modelIds.contains(model.getVersionId())) { + managementRoleList.add(managementMap); + } + } + } + data.put("managementList", managementRoleList); + } else { + data.put("managementList", new ArrayList()); + } + //技术标准 + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_TECHNICAL_STANDARD)) { + String technicalStandardId = controlPolicyIds.get(PublisherConstant.ORG_RELATION_TECHNICAL_STANDARD); + String publishedTechnicalStandardIds = getRelationPublishedControlIds(wsId, technicalStandardId, "control.policy"); + List> technicalList = publisherDao.getRelationFileIds(processIds, publishedTechnicalStandardIds); + List> technicalRoleList = new ArrayList>(); + if (technicalList != null && technicalList.size() > 0) { + for (Map managementMap : technicalList) { + String id = managementMap.get("id").toString(); + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (modelIds.contains(model.getVersionId())) { + technicalRoleList.add(managementMap); + } + } + } + data.put("technicalList", technicalRoleList); + } else { + data.put("technicalList", new ArrayList()); + } + //工作标准 + if (controlPolicyIds.containsKey(PublisherConstant.ORG_RELATION_WORK_STANDARD)) { + String workStandardId = controlPolicyIds.get(PublisherConstant.ORG_RELATION_WORK_STANDARD); + String publishedWorkStandardIds = getRelationPublishedControlIds(wsId, workStandardId, "control.policy"); + List> workList = publisherDao.getRelationFileIds(processIds, publishedWorkStandardIds); + List> workRoleList = new ArrayList>(); + if (workList != null && workList.size() > 0) { + for (Map managementMap : workList) { + String id = managementMap.get("id").toString(); + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (modelIds.contains(model.getVersionId())) { + workRoleList.add(managementMap); + } + } + } + data.put("workList", workRoleList); + } else { + data.put("workList", new ArrayList()); + } + } + return data; + } + + private String getRelationPublishedControlIds(String wsId, String pid, String methodId) { + List standardList = new ArrayList(); + PALRepositoryQueryAPIManager.getInstance().getAllPublishedPalRepositoryModelsByPid(wsId, pid, standardList); + String ids = ""; //已经发布的管理标准 + StringBuilder sbStandardIds = new StringBuilder("'" + pid + "'"); + if (standardList != null && standardList.size() > 0) { + for (PALRepositoryModel model : standardList) { + if (methodId == null || "".equals(methodId) || methodId.equals(model.getMethodId())) { + sbStandardIds.append(",'").append(model.getId()).append("'"); + } + } + } + ids = sbStandardIds.toString(); + return ids; + } + + /** + * 按组织维护流程 + * + * @param wsId + * @return + */ + public String getManageHome(String wsId, String categorys) { + Map result = new HashMap(); + result.put("sid", _uc.getSessionId()); + JSONArray treeData = new JSONArray(); + if (UtilString.isEmpty(wsId)) { + wsId = SDK.getAppAPI().getProperty(CoEConstant.APP_ID, CoEConstant.PROPERTY_DEFAULT_WSID); + } + result.put("wsId", wsId); + //根节点 + String[] categoryArray = categorys.split(","); + for (String category : categoryArray) { + category = category.trim(); + JSONObject categoryRoot = new JSONObject(); + categoryRoot.put("id", category); + categoryRoot.put("name", I18nRes.findValue(CoEConstant.APP_ID, category)); + categoryRoot.put("open", false); + categoryRoot.put("nocheck", true); + treeData.add(categoryRoot); + + //查询部门下的流程根节点 + List list = PALRepositoryQueryAPIManager.getInstance().getRootPALRepositoryModelsByDeptId(_uc.getUID(), wsId, null, category, true, false); + List newList = new ArrayList(); + for (PALRepositoryModel process : list) { + PALRepositoryModelImpl newProcess = (PALRepositoryModelImpl) process; + newProcess.setNewParentId(category); + newList.add((PALRepositoryModel) newProcess); + } + treeData.addAll(PALRepositoryQueryAPIManager.getInstance().list2Json(_uc, newList, true, false)); + } + result.put("treeData", treeData); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.manage.home.html", result); + } + + /** + * 已发布流程查询 + * + * @param wsId + * @param categorys + * @return + */ + public String getManageSearchHome(String wsId, String categorys) { + Map result = new HashMap(); + result.put("sid", _uc.getSessionId()); + if (UtilString.isEmpty(wsId)) { + wsId = SDK.getAppAPI().getProperty(CoEConstant.APP_ID, CoEConstant.PROPERTY_DEFAULT_WSID); + } + + JSONArray treeData = new JSONArray(); + PALRepositoryQueryAPIManager manager = PALRepositoryQueryAPIManager.getInstance(); + PALRepository dao = new PALRepository(); + String[] categoryList = categorys.split(","); + StringBuilder filePerms = new StringBuilder(""); + for (String category : categoryList) { + category = category.trim(); + + JSONObject root = new JSONObject(); + root.put("id", category); + root.put("name", I18nRes.findValue(CoEConstant.APP_ID, category)); + root.put("open", false); + treeData.add(root); + + List repositoryModelList = dao.searchRepositoryList(wsId, null, null, "", -1, null, null, null, null, null, null, -1, null, category, null, false, true, "", "", -1, null, "PLNO"); + for (PALRepositoryModel model : repositoryModelList) { + filePerms.append(model.getId()).append(","); + } + List newList = manager.setNewPid(repositoryModelList); + treeData.addAll(manager.list2Json(_uc, newList, false, true)); + } + + result.put("treeData", treeData); + result.put("filePerms", filePerms); + + result.put("wsId", wsId); + result.put("processRootId", SDK.getAppAPI().getProperty(PublisherConstant.PUBLISH, "processRootId")); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.search.home.html", result); + } + + /** + * 已发布流程查询 + * + * @param wsId + * @param categorys + * @return + */ + public String getManageSearchHomeCondition(String wsId, String categorys) { + Map result = new HashMap(); + result.put("sid", _uc.getSessionId()); + if (UtilString.isEmpty(wsId)) { + wsId = SDK.getAppAPI().getProperty(CoEConstant.APP_ID, CoEConstant.PROPERTY_DEFAULT_WSID); + } + + JSONArray treeData = new JSONArray(); + PALRepositoryQueryAPIManager manager = PALRepositoryQueryAPIManager.getInstance(); + PALRepository dao = new PALRepository(); + String[] categoryList = categorys.split(","); + StringBuilder filePerms = new StringBuilder(""); + for (String category : categoryList) { + category = category.trim(); + + JSONObject root = new JSONObject(); + root.put("id", category); + root.put("name", I18nRes.findValue(CoEConstant.APP_ID, category)); + root.put("open", false); + treeData.add(root); + + JSONArray params = new JSONArray(); + JSONObject param1 = new JSONObject(); + param1.put("key", "securityclass"); + param1.put("value", "='内部'"); + params.add(param1); + List repositoryModelList = dao.searchRepositoryList(wsId, null, null, "", -1, null, null, null, null, null, null, -1, null, category, null, false, true, "", "", -1, params, "PLNO"); + params = new JSONArray(); + JSONObject param2 = new JSONObject(); + param2.put("key", "securityclass"); + param2.put("value", "='外部公开'"); + params.add(param2); + repositoryModelList.addAll(dao.searchRepositoryList(wsId, null, null, "", -1, null, null, null, null, null, null, -1, null, category, null, false, true, "", "", -1, params, "PLNO")); + for (PALRepositoryModel model : repositoryModelList) { + filePerms.append(model.getId()).append(","); + } + List newList = manager.setNewPid(repositoryModelList); + treeData.addAll(manager.list2Json(_uc, newList, false, true)); + } + + result.put("treeData", treeData); + result.put("filePerms", filePerms); + + result.put("wsId", wsId); + result.put("processRootId", SDK.getAppAPI().getProperty(PublisherConstant.PUBLISH, "processRootId")); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.search.home.html", result); + } + + private boolean isEmpty(List list) { + return list == null || list.size() == 0; + } + + /** + * 获取当前人权限下的模型id + * 条件: + * 1.模型中有节点关联的是AWS平台的人员且人员与当前人相同 + * 2.模型中有关联节点是角色,且角色是当前人员的所属角色(包括兼职角色) + * 3.模型的文件属性中的责任人是当前人 + * 4.获取的流程文件的当前版本必须是已发布 + * @param uc + * @return + */ + private Set getAwsOrgPermRepositoryByUser(UserContext uc, String category, boolean isPublish) { + Set result = new HashSet<>(); + // 获取当前人的所有角色 + String userId = uc.getUID(); + Set roleIds = new HashSet<>(); + RoleModel roleModel = uc.getRoleModel(); + roleIds.add(roleModel.getId()); + // 兼职角色 + List userMapModels = UserMapCache.getMapListOfUser(userId); + if (!isEmpty(userMapModels)) { + for (UserMapModel role : userMapModels) { + roleIds.add(role.getRoleId()); + } + } + // 条件1,2,4 + List list = DesignerShapeRelationCache.getListByRelationShapeId("00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"); + if (!isEmpty(list)) { + for (DesignerShapeRelationModel model : list) { + JSONObject object = JSONObject.parseObject(model.getRelationShapeText()); + if ("user".equalsIgnoreCase(object.getString("type")) && uc.getUID().equals(object.getString("id"))) { + PALRepositoryModel p = PALRepositoryCache.getCache().get(model.getFileId()); + if (p != null) { + if (isPublish) { + if (p.isPublish()) { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } else { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } + } + if ("role".equalsIgnoreCase(object.getString("type")) && roleIds.contains(object.getString("id"))) { + PALRepositoryModel p = PALRepositoryCache.getCache().get(model.getFileId()); + if (p != null) { + if (isPublish) { + if (p.isPublish()) { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } else { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } + } + } + } + // 条件3,4 + CoeWorkSpace workSpace = new CoeWorkSpace(); + List wsList = workSpace.getNormalCoeWorkSpaceModelRecodes(); + if (!isEmpty(wsList)) { + for (CoeWorkSpaceModel model : wsList) { + Iterator iterator = PALRepositoryCache.getByWsId(model.getUUId()); + while (iterator.hasNext()) { + PALRepositoryModel pModel = iterator.next(); + if (pModel != null && pModel.getMethodCategory().equals(category) && userId.equals(pModel.getDutyUser())) { + if (isPublish) { + if (pModel.isPublish()) { + result.add(pModel.getId()); + } + } else { + result.add(pModel.getId()); + } + } + } + } + } + return result; + } + + /** + * 获取当前人权限下的模型id + * 条件: + * 1.模型中有节点关联的是AWS平台的人员且人员与当前人相同 + * 2.模型中有关联节点是角色,且角色是当前人员的所属角色(包括兼职角色) + * 3.获取的流程文件的当前版本必须是已发布 + * @param uc + * @return + */ + private Set getAwsOrgPermRealtionRepositoryByUser(UserContext uc, String category, boolean isPublish) { + Set result = new HashSet<>(); + // 获取当前人的所有角色 + String userId = uc.getUID(); + Set roleIds = new HashSet<>(); + RoleModel roleModel = uc.getRoleModel(); + roleIds.add(roleModel.getId()); + // 兼职角色 + List userMapModels = UserMapCache.getMapListOfUser(userId); + if (!isEmpty(userMapModels)) { + for (UserMapModel role : userMapModels) { + roleIds.add(role.getRoleId()); + } + } + // 条件1,2,3 + List list = DesignerShapeRelationCache.getListByRelationShapeId("00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"); + if (!isEmpty(list)) { + for (DesignerShapeRelationModel model : list) { + JSONObject object = JSONObject.parseObject(model.getRelationShapeText()); + if ("user".equalsIgnoreCase(object.getString("type")) && uc.getUID().equals(object.getString("id"))) { + PALRepositoryModel p = PALRepositoryCache.getCache().get(model.getFileId()); + if (p != null) { + if (isPublish) { + if (p.isPublish()) { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } else { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } + } + if ("role".equalsIgnoreCase(object.getString("type")) && roleIds.contains(object.getString("id"))) { + PALRepositoryModel p = PALRepositoryCache.getCache().get(model.getFileId()); + if (p != null) { + if (isPublish) { + if (p.isPublish()) { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } else { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } + } + } + } + return result; + } + + /** + * 获取责任人是当前人的模型id + * 条件: + * 1.模型的文件属性中的责任人是当前人 + * @param uc + * @return + */ + private Set getPermRepositoryByDutyPerson(UserContext uc, String category, boolean isPublish) { + Set result = new HashSet<>(); + // 获取当前人的所有角色 + String userId = uc.getUID(); + // 条件3,4 + CoeWorkSpace workSpace = new CoeWorkSpace(); + List wsList = workSpace.getNormalCoeWorkSpaceModelRecodes(); + if (!isEmpty(wsList)) { + for (CoeWorkSpaceModel model : wsList) { + Iterator iterator = PALRepositoryCache.getByWsId(model.getUUId()); + while (iterator.hasNext()) { + PALRepositoryModel pModel = iterator.next(); + if (pModel != null && pModel.getMethodCategory().equals(category) && userId.equals(pModel.getDutyUser())) { + if (isPublish) { + if (pModel.isPublish()) { + result.add(pModel.getId()); + } + } else { + result.add(pModel.getId()); + } + } + } + } + } + return result; + } + + /** + * 获取当前人给定部门时权限下的模型id + * 模型中有关联节点是部门,且角色是当前人员的所属角色(包括兼职角色) + * @param uc + * @param category + * @param deptId + * @return + */ + private Set getAwsOrgPermRepositoryByDept(UserContext uc, String category, String deptId, boolean isPublish) { + Set result = new HashSet<>(); + List list = DesignerShapeRelationCache.getListByRelationShapeId("00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"); + if (!isEmpty(list)) { + for (DesignerShapeRelationModel model : list) { + JSONObject object = JSONObject.parseObject(model.getRelationShapeText()); + if ("department".equalsIgnoreCase(object.getString("type")) && deptId.equals(object.getString("id"))) { + PALRepositoryModel p = PALRepositoryCache.getCache().get(model.getFileId()); + if (p != null && p.isPublish()) { + if (isPublish) { + if (p.isPublish()) {// 已发布 + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } else { + if (UtilString.isEmpty(category)) { + result.add(p.getId()); + } else { + if (p.getMethodCategory().equals(category)) { + result.add(p.getId()); + } + } + } + } + } + } + } + return result; + } + + /** + * 获取当前人权限下的资产库id集合 + * @param uc + * @return + */ + private Set getAwsOrgPermWsByUser(UserContext uc, String category) { + Set wsIds = new HashSet<>(); + Set repositoryIds = getAwsOrgPermRepositoryByUser(uc, category, true); + for (String repositoryId : repositoryIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(repositoryId); + if (model != null && PALRepositoryQueryAPIManager.getInstance().isActiveWorkSpace(model.getWsId())) + wsIds.add(model.getWsId()); + } + return wsIds; + } + + /** + * 根据userId获取具有权限的已发布资产库 + * @return + */ + private List> getPermRepositoryVersionIdByUser(UserContext uc, String roleId) { + // 获取资产库流程Id + PALRepository dao = new PALRepository(); + List> wsList = dao.getWorkSpaceListByPublishRole(roleId, true, true); // 有访问权限的资产库 + if (wsList != null && wsList.size() > 0) { + List> removeList = new ArrayList>(); + for (Map ws : wsList) { + boolean isActive = PALRepositoryQueryAPIManager.getInstance().isActiveWorkSpace(ws.get("wsId")); + if (!isActive) { + removeList.add(ws); + } + } + wsList.removeAll(removeList); + } + return wsList; + } + + /** + * 根据userId获取具有权限的已发布资产库 + * pal自身权限+关联AWS平台权限 + * @return + */ + private List> getPalAndAwsPermRepositoryVersionIdByUser(UserContext uc, String roleId, String category) { + // 获取资产库流程Id + PALRepository dao = new PALRepository(); + //List> wsList = dao.getWorkSpaceListByPublishRole(roleId, true, true); // 有访问权限的资产库 + List> wsList = dao.getWorkSpaceListByPublishRole(roleId, false, true); // 有访问权限的资产库(发布+未发布) + if (wsList != null && wsList.size() > 0) { + List> removeList = new ArrayList>(); + for (Map ws : wsList) { + boolean isActive = PALRepositoryQueryAPIManager.getInstance().isActiveWorkSpace(ws.get("wsId")); + if (!isActive) { + removeList.add(ws); + } + } + wsList.removeAll(removeList); + } + // 关联AWS组织的资产库权限整合 + if (wsList == null) { + wsList = new ArrayList<>(); + } + Set wsIds = getAwsOrgPermWsByUser(uc, category); + if (wsIds.size() > 0) { + Set temp = new HashSet<>(); + for (Map ws : wsList) { + temp.add(ws.get("wsId")); + } + CoeWorkSpace wsDao = new CoeWorkSpace(); + for (String wsId : wsIds) { + if (!temp.contains(wsId)) { + CoeWorkSpaceModel model = wsDao.getInstance(wsId); + if (model != null) { + Map result = new HashMap<>(); + result.put("wsId", model.getUUId()); + result.put("wsName", model.getWsName()); + wsList.add(result); + } + } + } + } + return wsList; + } + + /** + * 获取基本参数 + * @param uc + * @param count + * @return + */ + private JSONObject getXPagesBasicParam(UserContext uc, String count) { + String isIntegrationAWSUser = SDK.getAppAPI().getProperty(PublisherConstant.PUBLISH, "isIntegrationAWSUser"); //是否整合AWS用户 + String roleId = ""; + if ("false".equals(isIntegrationAWSUser)) { + roleId = PublishConst.GUESTROLE; + } else { + roleId = uc.getRoleModel().getId(); + } + + boolean limit = true;// 是否限制条数,count为空则不限制 + int c = 0; + if(!UtilString.isEmpty(count)){ + c = Integer.parseInt(count); + } else { + limit = false; + } + JSONObject object = new JSONObject(); + object.put("roleId", roleId); + object.put("c", c); + object.put("limit", limit); + return object; + } + + /** + * 常用流程查询 + * xpages小页面 + * @param count + * @return + */ + public String commonProcessQuery(UserContext uc, String count) { + String category = "process"; + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + JSONObject param = getXPagesBasicParam(uc, count); + String roleId = param.getString("roleId"); + boolean limit = param.getBooleanValue("limit"); + int c = param.getIntValue("c"); + PublishListHistory pHistory = new PublishListHistory(); + JSONArray array = new JSONArray(); + // 获取常用流程数据 + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, category); + if (wsList != null && wsList.size() > 0) { + PublishCommonDao commonDao = new PublishCommonDao(); + + StringBuffer wsIds = new StringBuffer(); + String sqlParam = ""; + for (Map map : wsList) { + wsIds.append("'").append(map.get("wsId")).append("'").append(","); + } + if (wsIds.length() > 0) { + sqlParam = wsIds.substring(0, wsIds.length() - 1); + } + // 获取降序排列的数据 + Object [] commons = commonDao.getCommonDataByWsIds(sqlParam, category); + @SuppressWarnings("unchecked") + List list = (ArrayList) commons[0];// 按照设定顺序升序排序的id集合 + JSONObject datas = (JSONObject) commons[1]; + if (list != null && list.size() > 0) { + PALRepository repositoryDao = new PALRepository(); + Set versionIds = repositoryDao.getRepositoryVersionIdListByPublishRole(roleId, sqlParam, category); + Set repositoryIds = getAwsOrgPermRepositoryByUser(uc, category, true);// aws平台下的资产库流程文件 + for (String str : repositoryIds) { + versionIds.add(PALRepositoryCache.getCache().get(str).getVersionId()); + } + int index = 0; + List list1 = new ArrayList<>(); + for (String id : list) { + if (limit && index >= c) break; + JSONObject data = datas.getJSONObject(id); + int sort = data.getIntValue("sort"); + //将sort为0的数据单独提出来 + if (sort == 0) { + list1.add(data); + continue; + } + List temps = PALRepositoryCache.getByVersionId(data.getString("wsId"), data.getString("plversionId")); + if (temps == null || temps.size() == 0) continue; + for (PALRepositoryModel model : temps) { + if (model.isPublish() && versionIds.contains(model.getVersionId())) { + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("versionId", model.getVersionId()); + object.put("method", model.getMethodId()); + object.put("date", model.getPublishDate() == null ? "" : model.getPublishDate()); + String taskId = pHistory.getLastPublishTaskIdByModelId(model.getId()); + object.put("taskId", taskId == null ? "" : taskId); + array.add(object); + index++; + break; + } + } + } + //将sort为0的数据放在数组的末尾 + for (JSONObject data:list1) { + if (limit && index >= c) break; + List temps = PALRepositoryCache.getByVersionId(data.getString("wsId"), data.getString("plversionId")); + if (temps == null || temps.size() == 0) continue; + for (PALRepositoryModel model : temps) { + if (model.isPublish() && versionIds.contains(model.getVersionId())) { + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("versionId", model.getVersionId()); + object.put("method", model.getMethodId()); + object.put("date", model.getPublishDate() == null ? "" : model.getPublishDate()); + String taskId = pHistory.getLastPublishTaskIdByModelId(model.getId()); + object.put("taskId", taskId == null ? "" : taskId); + array.add(object); + index++; + break; + } + } + } + } + } + result.put("data", array); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.common.html", result); + } + + /** + * 高频流程查询 + * @param uc + * @param count + * @return + */ + public String frequencyProcessQuery(UserContext uc, String count) { + String category = "process"; + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + JSONObject param = getXPagesBasicParam(uc, count); + String roleId = param.getString("roleId"); + boolean limit = param.getBooleanValue("limit"); + int c = param.getIntValue("c"); + + JSONArray array = new JSONArray(); + // 获取高频流程记录数据 + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, category); + if (wsList != null && wsList.size() > 0) { + PublishFrequencyDao frequencyDao = new PublishFrequencyDao(); + StringBuffer wsIds = new StringBuffer(); + String sqlParam = ""; + for (Map map : wsList) { + wsIds.append("'").append(map.get("wsId")).append("'").append(","); + } + if (wsIds.length() > 0) { + sqlParam = wsIds.substring(0, wsIds.length() - 1); + } + Object [] frequencyModels = frequencyDao.getDatasOrderByCount(sqlParam, category); + @SuppressWarnings("unchecked") + List list = (ArrayList) frequencyModels[0];// 按照访问量降序排序的id集合 + JSONObject datas = (JSONObject) frequencyModels[1]; + PublishListHistory pHistory = new PublishListHistory(); + // 获取所有节点 + if (list != null && list.size() > 0) { + PALRepository repositoryDao = new PALRepository(); + Set versionIds = repositoryDao.getRepositoryVersionIdListByPublishRole(roleId, sqlParam, category); + Set repositoryIds = getAwsOrgPermRepositoryByUser(uc, category, true);// aws平台下的资产库流程文件 + for (String str : repositoryIds) { + versionIds.add(PALRepositoryCache.getCache().get(str).getVersionId()); + } + int index = 0; + for (String id : list) { + if (limit && index >= c) break; + JSONObject data = datas.getJSONObject(id); + List temps = PALRepositoryCache.getByVersionId(data.getString("wsId"), data.getString("plversionId")); + if (temps == null || temps.size() == 0) continue; + for (PALRepositoryModel model : temps) { + if (model.isPublish() && versionIds.contains(model.getVersionId())) { + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("versionId", model.getVersionId()); + object.put("count", data.getString("count")); + object.put("method", model.getMethodId()); + object.put("date", model.getPublishDate() == null ? "" : model.getPublishDate()); + String taskId = pHistory.getLastPublishTaskIdByModelId(model.getId()); + object.put("taskId", taskId == null ? "" : taskId); + array.add(object); + index++; + break; + } + } + } + } + } + result.put("data", array); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.frequency.html", result); + } + + /** + * 系统、数据、组织、控制模型查询 + * @param count + * @return + */ + public String queryDataBycategory(UserContext uc, String count, String category, String page) { + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + JSONObject param = getXPagesBasicParam(uc, count); + String roleId = param.getString("roleId"); + boolean limit = param.getBooleanValue("limit"); + int c = param.getIntValue("c"); + JSONArray array = new JSONArray(); + // 获取系统模型数据 + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, category); + if (wsList != null && wsList.size() > 0) { + + StringBuffer wsIds = new StringBuffer(); + String sqlParam = ""; + for (Map map : wsList) { + wsIds.append("'").append(map.get("wsId")).append("'").append(","); + } + if (wsIds.length() > 0) { + sqlParam = wsIds.substring(0, wsIds.length() - 1); + } + int index = 0; + PALRepository dao = new PALRepository(); + List plList = dao.getRepositoryListByPublishRoleAndCategory(roleId, sqlParam, category); + Set repositoryIds = getAwsOrgPermRepositoryByUser(uc, category, true);// aws平台下的资产库流程文件 + // 整合PAL自身权限文件和关联AWS的权限文件 + if (repositoryIds != null && repositoryIds.size() > 0) { + // 整合完成之后重新排序,按照发布时间,层级,顺序排序 + if (plList == null) { + plList = new ArrayList<>(); + } + Set idSet = new HashSet<>(); + for (PALRepositoryModel plModel : plList) { + idSet.add(plModel.getId()); + } + for (String id : repositoryIds) { + if (!idSet.contains(id)) { + plList.add(PALRepositoryCache.getCache().get(id)); + } + } + // 排序 + Collections.sort(plList, new Comparator() { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + Timestamp p1 = o1.getPublishDate(); + Timestamp p2 = o2.getPublishDate(); + if (!p1.equals(p2)) { + return p2.compareTo(p1); + } + int level1 = o1.getLevel(); + int level2 = o2.getLevel(); + if (level1 != level2) { + return level1 - level2; + } + int order1 = o1.getOrderIndex(); + int order2 = o2.getOrderIndex(); + return order1 - order2; + } + }); + } + if (plList != null && plList.size() > 0) { + for (PALRepositoryModel plModel : plList) { + JSONObject object = new JSONObject(); + object.put("id", plModel.getId()); + object.put("name", plModel.getName()); + object.put("versionId", plModel.getVersionId()); + object.put("date", plModel.getPublishDate() == null ? "" : plModel.getPublishDate()); + object.put("method", plModel.getMethodId()); + object.put("taskId", ""); + array.add(object); + index++; + if (limit && index >= c) { + break; + } + } + } + } + result.put("data", array); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages." + page + ".html", result); + } + + + + /** + * 发布动态 + * @param count + * @return + */ + public String queryNotificationData(UserContext uc, String start, String count) { + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + JSONObject param = getXPagesBasicParam(uc, count); + String roleId = param.getString("roleId"); + int startNum = -1; + if (!UtilString.isEmpty(start)) { + startNum = Integer.parseInt(start); + } + int limitNum = 10; + if (!UtilString.isEmpty(count)) { + limitNum = Integer.parseInt(count); + } + JSONArray array = new JSONArray(); + PublishListHistory dao = new PublishListHistory(); + // 获取所有的发布历史 + List modelList = dao.getPublishListHistory(); + if (!isEmpty(modelList)) { + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + palProcessIds.add(model.getId()); + } + } + } + // 获取关联AWS组织的版本ID且当前为已发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(uc, null, true); + // 整合所有权限 + for (String id : awsProcessIds) { + String tempVer = PALRepositoryCache.getCache().get(id).getVersionId(); + if (!palProcessIds.contains(tempVer)) { + palProcessIds.add(tempVer); + } + } + int index = 0; + for (PublishListHistoryModel model : modelList) { + if (index >= limitNum) { + break; + } + if (!palProcessIds.contains(model.getPalRepositoryId())) + continue; + PALRepositoryModel repositoryModel = PALRepositoryCache.getCache().get(model.getPalRepositoryId()); + if (repositoryModel == null) { + continue; + } + JSONObject object = new JSONObject(); + String actionType = model.getActionType(); + object.put("type", actionType); + object.put("date", model.getPublishDate()); + String intro = ""; + if ("N".equals(actionType)) { + intro = "新发布"; + } else if ("C".equals(actionType)) { + intro = "变更"; + } else if ("S".equals(actionType)) { + intro = "停用"; + } + object.put("intro", intro); + object.put("method", repositoryModel.getMethodId()); + object.put("desc", model.getPublishDesc()); + object.put("pid", model.getpId()); + PublishHistoryModel pModel = PublishHistoryCache.getModel(model.getpId()); + object.put("pDesc", pModel.getPublishDesc()); + object.put("id", model.getPalRepositoryId()); + object.put("name", repositoryModel.getName()); + object.put("version", VersionUtil.getVersionStr(repositoryModel.getVersion())); + object.put("isPublish", repositoryModel.isPublish() ? "1" : "0"); + String taskId = model.getTaskId(); + object.put("taskId", taskId == null ? "" : taskId); + array.add(object); + index ++; + } + } + result.put("data", array); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.notification.html", result); + } + + /** + * xpages配置流程地图时查询资产库列表和平台单位列表 + * @param uc + * @return + */ + public String processmapWsAndOrgDataQuery(UserContext uc) { + ResponseObject ro = ResponseObject.newOkResponse(); + // 获取启用中的资产库 + List wsList = CoeWorkSpaceDaoFactory.createCoeWorkSpace().getCoeWorkSpaceModelRecodesNoPage(); + JSONArray wsArray = new JSONArray(); + if (!isEmpty(wsList)) { + for (CoeWorkSpaceModel ws : wsList) { + if (ws.getWsState() == 0) { + JSONObject object = new JSONObject(); + object.put("text", ws.getWsName()); + object.put("id", ws.getUUId()); + wsArray.add(object); + } + } + } + // 获取未注销的平台单位 + List cList = SDK.getORGAPI().getCompanys(); + JSONArray orgArray = new JSONArray(); + if (!isEmpty(cList)) { + for (CompanyModel company: cList) { + JSONObject object = new JSONObject(); + object.put("text", company.getName()); + object.put("id", company.getId()); + orgArray.add(object); + } + } + ro.put("wsData", wsArray); + ro.put("orgData", orgArray); + return ro.toString(); + } + + /** + * 流程地图 + * @param orgId + * @param wsId + * @return + */ + public String queryProcessmapData(UserContext uc, String wsId, String orgId) { + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + // 获取资产库一级流程 + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, "process"); + // wsId在wsList内则取wsId,不在则取wsList中第一个元素 + if (wsList != null && wsList.size() > 0) { + Set wsIds = new HashSet<>(); + for (Map map : wsList) { + wsIds.add(map.get("wsId")); + } + if (UtilString.isEmpty(wsId) || !wsIds.contains(wsId)) { + wsId = wsList.get(0).get("wsId"); + } + } + // 获取三个一级流程 + JSONArray processData = getUsedModelsByPid(roleId, wsId, "process"); + result.put("processData", processData); + + // 获取组织架构 + List orgList = SDK.getORGAPI().getCompanys(); + if (orgList != null && orgList.size() > 0) { + Set orgIds = new HashSet<>(); + for (int i = 0; i < orgList.size(); i++) { + if (orgList.get(i).isClosed()) { + continue; + } + orgIds.add(orgList.get(i).getId()); + } + if (UtilString.isEmpty(orgId) || !orgIds.contains(orgId)) { + orgId = orgList.get(0).getId(); + } + } + // 获取三个部门 + JSONArray deptData = getDeptsByCompany(orgId); + result.put("deptData", deptData); + result.put("wsId", wsId); + result.put("orgId", orgId); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.processmap.html", result); + } + + /** + * 获取3个一级部门 + * @param orgId + * @return + */ + private JSONArray getDeptsByCompany(String orgId) { + JSONArray result = new JSONArray(); + List list = SDK.getORGAPI().getDepartmentsByCompanyId(1, orgId); + int index = 0; + for (DepartmentModel model : list) { + if (model.isClosed()) { + continue; + } + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + result.add(object); + index++; + if (index >= 3) { + break; + } + } + return result ; + } + + // 当同一个version流程存在已发布和使用中的,过滤掉使用中的 + private List filterPublisherData(List list) { + if (list != null && list.size() > 0) { + List tempList = new ArrayList<>(); + Set idSet = new HashSet<>(); + for (PALRepositoryModel model : list) { + if (model.isPublish()) { + idSet.add(model.getVersionId()); + tempList.add(model); + } + } + for (PALRepositoryModel model : list) { + if (model.isUse() && !idSet.contains(model.getVersionId())) { + tempList.add(model); + } + } + list = tempList; + } + return list; + } + + /** + * 获取3个一级流程 + * @param wsId + * @param parentId + * @return + */ + private JSONArray getUsedModelsByPid(String roleId, String wsId, String parentId) { + JSONArray result = new JSONArray(); + if (!UtilString.isEmpty(wsId)) { + @SuppressWarnings("unchecked") + List list = IteratorUtils.toList(PALRepositoryCache.getByPid(wsId, "process")); + list = filterPublisherData(list); + if (list != null && list.size() > 0) { + // 排列 + Collections.sort(list, new Comparator() { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + return o1.getOrderIndex() > o2.getOrderIndex() ? 1 : o1.getOrderIndex() < o2.getOrderIndex() ? -1 : 0; + } + }); + PALRepository dao = new PALRepository(); + Set idSet = dao.getRepositoryVersionIdListByPublishRole(roleId, "'" + wsId + "'", "process"); + Set relationAwsIdSet = getAwsOrgPermRepositoryByUser(_uc, "process", true); + if (relationAwsIdSet != null && relationAwsIdSet.size() > 0) { + for (String awsId : relationAwsIdSet) { + idSet.add(awsId); + } + } + int index = 0; + for (PALRepositoryModel model : list) { + boolean flag = false; + if (model.isPublish() && idSet.contains(model.getVersionId())) { + flag = true; + } else { + Set ids = new HashSet<>(); + List subList = new ArrayList<>(); + PALRepositoryCache.getAllChildrenModelsByPid(wsId, model.getId(), subList, ids); + if (subList != null && subList.size() > 0) { + for (PALRepositoryModel subModel : subList) { + if (subModel.isPublish() && idSet.contains(subModel.getVersionId())) { + flag = true; + break; + } + } + } + } + if (flag) { + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + result.add(object); + index++; + } + if (index >= 3) { + break; + } + } + } + } + return result; + } + + /** + * 搜索 + * @param uc + * @param text 搜索文本 + * @param type 类型 + * @param templateId xpagesId + * @param wsId 默认展示的流程资产库id + * @return + */ + public String search(UserContext uc, String text, String type, String templateId, String wsId) { + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + result.put("text", text); + result.put("type", type); + result.put("templateId", templateId); + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + // List> wsList = getPermRepositoryVersionIdByUser(uc, roleId); + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, null); + JSONArray ws = new JSONArray(); + if (wsList != null && wsList.size() > 0) { + for (int i = 0; i < wsList.size(); i++) { + JSONObject object = new JSONObject(); + object.put("id", wsList.get(i).get("wsId")); + object.put("text", wsList.get(i).get("wsName")); + if(wsId!=null && wsId.equals(wsList.get(i).get("wsId"))) { + object.put("initDisplay", "1"); //默认使用的流程资产库 + } else { + object.put("initDisplay", "0"); + } + ws.add(object); + } + } + result.put("ws", ws); + + JSONArray scope = new JSONArray(); + JSONObject object = new JSONObject(); + object.put("name", "已发布文件"); + object.put("type", "all"); + scope.add(object); + + // alsp获取xpages数据 + // 调用App + String sourceAppId = PublisherConf.APPID; + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.addons.xpages/queryCwListByTemplateId"; + // 参数定义列表 + Map params = new HashMap(); + //模板id,必填 + params.put("templateId", templateId); + params.put("sid", uc.getSessionId()); + AppAPI appAPI = SDK.getAppAPI(); + //查询模板信息 + ResponseObject xpagesList = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + JSONObject data = JSONObject.parseObject(xpagesList.toDataString()); + JSONArray cwList = data.getJSONArray("cwList"); + for (int i = 0; i < cwList.size(); i++) { + JSONObject obj = cwList.getJSONObject(i).getJSONArray("subList").getJSONObject(0); + JSONObject obj2 = new JSONObject(); + if (obj.getString("cwUrl").contains("com.actionsoft.apps.publisher_xpages_banner_msg")) { + continue; + } + obj2.put("name", obj.getString("cwName")); + String url = obj.getString("cwUrl"); + if (!url.contains("com.actionsoft.apps.publisher_xpages_")) {// 识别PAL流程发布默认的xpages + continue; + } + String type2 = url.substring(url.indexOf("xpages_") + 7, url.indexOf("_msg")); + obj2.put("type", type2); + scope.add(obj2); + } + result.put("scope", scope); + JSONObject logoObject = getLogoImgPath(uc); + result.put("logoImgPath", logoObject.getString("src")); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.search.html", result); + } + + /** + * 查询数据 + * @param searchText + * @param searchType + * @param searchWsId + * @param start + * @param pageLimit + * @return + */ + public String searchData(UserContext uc, String searchText, String searchType, String searchWsId, int start, int pageLimit) { + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + String wsIdsql = ""; + if (UtilString.isEmpty(searchWsId)) { + // List> wsList = getPermRepositoryVersionIdByUser(uc, roleId); + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, null); + if (wsList != null && wsList.size() > 0) { + StringBuffer wsIds = new StringBuffer(); + for (Map map : wsList) { + wsIds.append("'").append(map.get("wsId")).append("'").append(","); + } + if (wsIds.length() > 0) { + wsIdsql = wsIds.substring(0, wsIds.length() - 1); + } + } + } else { + wsIdsql = "'" + searchWsId + "'"; + } + switch (searchType) { + case "all":// 已发布文件 + return getAllPublishedData(searchText, wsIdsql, roleId, start, pageLimit, null); + case "common":// 常用流程 + return getPublishedCommonData(searchText, wsIdsql, roleId, start, pageLimit, "process"); + case "frequency":// 高频流程 + return getPublishedFrequencyData(searchText, wsIdsql, roleId, start, pageLimit, "process"); + case "system":// 系统地图 + return getAllPublishedData(searchText, wsIdsql, roleId, start, pageLimit, "itsystem"); + case "data":// 数据地图 + return getAllPublishedData(searchText, wsIdsql, roleId, start, pageLimit, "data"); + case "control":// 控制地图 + return getAllPublishedData(searchText, wsIdsql, roleId, start, pageLimit, "control"); + case "org":// 组织地图 + return getAllPublishedData(searchText, wsIdsql, roleId, start, pageLimit, "org"); + case "processmap":// 流程地图 + return getAllPublishedData(searchText, wsIdsql, roleId, start, pageLimit, "process"); + default:// 通知公告 + return getPublishNotificationData(searchText, wsIdsql, roleId, start, pageLimit, null); + } + } + + private String getPublishNotificationData(String searchText, String wsIdsql, String roleId, int start, int pageLimit, String category) { + ResponseObject ro = ResponseObject.newOkResponse(); + PublishListHistory dao = new PublishListHistory(); + List modelList = dao.getPublishListHistoryByRole(roleId, null, wsIdsql, searchText); + + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + palProcessIds.add(model.getId()); + } + } + } + // 获取关联AWS组织的版本ID且当前为已发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, null, true); + // 整合所有权限 + for (String id : awsProcessIds) { + String tempVer = PALRepositoryCache.getCache().get(id).getVersionId(); + if (!palProcessIds.contains(tempVer)) { + palProcessIds.add(tempVer); + } + } + + // 过滤最终结果 + List list = new ArrayList<>(); + for (JSONObject object : modelList) { + String repositoryId = object.getString("repositoryId"); + if (palProcessIds.contains(repositoryId)) { + list.add(object); + } + } + List subList = null; + int end = start + pageLimit; + if (start > list.size() - 1) { + subList = new ArrayList<>(); + } else if (list.size() >= end) { + subList = list.subList(start, end); + } else { + subList = list.subList(start, list.size()); + } + JSONArray result = new JSONArray(); + for (JSONObject object : subList) { + JSONObject object2 = new JSONObject(); + String repositoryId = object.getString("repositoryId"); + PALRepositoryModel palModel = PALRepositoryCache.getCache().get(repositoryId); + object2.put("id", palModel.getId()); + object2.put("version", palModel.getVersion()); + String userName = ""; + if (UserCache.getModel(object.getString("userId")) != null) { + userName = UserCache.getModel(object.getString("userId")).getUserName(); + } + + String actionType = object.getString("actionType"); + String intro = ""; + switch (actionType) { + case "N": + intro = "新发布"; + break; + case "C": + intro = "变更"; + break; + default:// S + intro = "停用"; + break; + } + object2.put("name", palModel.getName() + "[" + intro + "]"); + object2.put("user", userName); + object2.put("dept", getDeptPath(object.getString("userId"))); + object2.put("date", object.getTimestamp("publishDate")); + object2.put("desc", object.getString("publishDesc")); + object2.put("isPublish", palModel.isPublish() ? "1" : "0"); + object2.put("taskId", object.containsKey("taskId") ? object.getString("taskId") : ""); + // 获取路径 + StringBuilder sBuilder = new StringBuilder();// 名称组合 + Set idSets = new HashSet<>();// id记录,校验防止递归死循环 + sBuilder.append(palModel.getName()); + idSets.add(palModel.getId()); + getFilePath(palModel, sBuilder,idSets);// 递归获取当前文件名称路径 + object2.put("path", sBuilder.toString()); + result.add(object2); + } + ro.put("data", result); + ro.put("count", result.size()); + return ro.toString(); + } + + /** + * 获取部门路径 + * @param userId + * @return + */ + private String getDeptPath(String userId) { + StringBuilder sBuilder = new StringBuilder();// 名称组合 + Set idSets = new HashSet<>();// id记录,校验防止递归死循环 + if (!UtilString.isEmpty(userId)) { + DepartmentModel model = SDK.getORGAPI().getDepartmentByUser(userId); + sBuilder.append(model.getName()); + idSets.add(model.getId()); + getDeptPath(model, sBuilder, idSets); + } + return sBuilder.toString(); + } + + private void getDeptPath(DepartmentModel model, StringBuilder sBuilder, Set idSets) { + if (!"0".equals(model.getId())) { + if (!idSets.contains(model.getParentDepartmentId())) { + String parentId = model.getParentDepartmentId(); + DepartmentModel parentModel = SDK.getORGAPI().getDepartmentById(parentId); + if (parentModel != null) { + sBuilder.insert(0, parentModel.getName() + ">"); + idSets.add(parentModel.getId()); + getDeptPath(parentModel, sBuilder, idSets); + } + } + } else { + sBuilder.insert(0, model.getName() + ">"); + } + } + + // 获取高频流程列表 + private String getPublishedFrequencyData(String searchText, String wsIdsql, String roleId, int start, int pageLimit, String category) { + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepository dao = new PALRepository(); + List list = dao.getRepositoryFrequencyListByPublishRole(wsIdsql, roleId, searchText, category); + if (list == null) { + list = new ArrayList<>(); + } + Set idSet = new HashSet<>(); + for (PALRepositoryModel model : list) { + idSet.add(model.getId()); + } + // 添加关联aws组织的流程进行合并 + boolean flag = false; + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + if (awsProcessIds != null && awsProcessIds.size() > 0) { + for (String processId : awsProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(processId); + if (model != null && wsIdsql.indexOf(model.getWsId()) > -1 && !idSet.contains(model.getId()) && model.getName().indexOf(searchText) > -1) { + list.add(model); + idSet.add(model.getId()); + flag = true; + } + } + } + if (flag) {// 合并过数据则需要重新排序 + // 排序 + Collections.sort(list, new MyComparator()); + } + List subList = null; + int end = start + pageLimit; + if (start > list.size() - 1) { + subList = new ArrayList<>(); + } else if (list.size() >= end) { + subList = list.subList(start, end); + } else { + subList = list.subList(start, list.size()); + } + JSONArray result = assembleData(subList); + ro.put("data", result); + ro.put("count", result.size()); + return ro.toString(); + } + + // 获取常用流程列表 + private String getPublishedCommonData(String searchText, String wsIdsql, String roleId, int start, int pageLimit, String category) { + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepository dao = new PALRepository(); + // List list = dao.getRepositoryCommonListByPublishRolePagination(wsIdsql, roleId, searchText, start, pageLimit, category); + List list = dao.getRepositoryCommonListByPublishRole(wsIdsql, roleId, searchText, category); + if (list == null) { + list = new ArrayList<>(); + } + Set idSet = new HashSet<>(); + for (PALRepositoryModel model : list) { + idSet.add(model.getId()); + } + // 添加关联aws组织的流程进行合并 + boolean flag = false; + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + if (awsProcessIds != null && awsProcessIds.size() > 0) { + for (String processId : awsProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(processId); + if (model != null && wsIdsql.indexOf(model.getWsId()) > -1 && !idSet.contains(model.getId()) && model.getName().indexOf(searchText) > -1) { + list.add(model); + idSet.add(model.getId()); + flag = true; + } + } + } + if (flag) {// 合并过数据则需要重新排序 + // 排序 + Collections.sort(list, new MyComparator()); + } + List subList = null; + int end = start + pageLimit; + if (start > list.size() - 1) { + subList = new ArrayList<>(); + } else if (list.size() >= end) { + subList = list.subList(start, end); + } else { + subList = list.subList(start, list.size()); + } + JSONArray result = assembleData(subList); + ro.put("data", result); + ro.put("count", result.size()); + return ro.toString(); + } + + // 获取已发布文件列表 + private String getAllPublishedData(String searchText, String wsIdsql, String roleId, int start, int pageLimit, String category) { + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepository dao = new PALRepository(); + List list = dao.getRepositoryListByPublishRole(wsIdsql, roleId, searchText, category); + if (list == null) { + list = new ArrayList<>(); + } + Set idSet = new HashSet<>(); + for (PALRepositoryModel model : list) { + idSet.add(model.getId()); + } + // 添加关联aws组织的流程进行合并 + boolean flag = false; + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + if (awsProcessIds != null && awsProcessIds.size() > 0) { + for (String processId : awsProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(processId); + if (model != null && wsIdsql.indexOf(model.getWsId()) > -1 && !idSet.contains(model.getId()) && model.getName().indexOf(searchText) > -1) { + list.add(model); + idSet.add(model.getId()); + flag = true; + } + } + } + if (flag) {// 合并过数据则需要重新排序 + // 排序 + Collections.sort(list, new MyComparator()); + } + List subList = null; + int end = start + pageLimit; + if (start > list.size() - 1) { + subList = new ArrayList<>(); + } else if (list.size() >= end) { + subList = list.subList(start, end); + } else { + subList = list.subList(start, list.size()); + } + JSONArray result = assembleData(subList); + ro.put("data", result); + ro.put("count", result.size()); + return ro.toString(); + } + + private class MyComparator implements Comparator { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + Timestamp p1 = o1.getPublishDate(); + Timestamp p2 = o2.getPublishDate(); + if (p1 != null && p2 != null) { + if (!p1.equals(p2)) { + return p2.compareTo(p1); + } + } + int level1 = o1.getLevel(); + int level2 = o2.getLevel(); + if (level1 != level2) { + return level1 - level2; + } + int order1 = o1.getOrderIndex(); + int order2 = o2.getOrderIndex(); + return order1 - order2; + } + } + + // 查询发布信息,拼接结果json + private JSONArray assembleData(List list) { + PublishListHistory pHistory = new PublishListHistory(); + JSONArray result = new JSONArray(); + // 获取已发布分页数据 + for (int i = 0; i < list.size(); i++) { + PALRepositoryModel model = list.get(i); + JSONObject object = pHistory.getLastPublishByModelId(model.getId()); + JSONObject object2 = new JSONObject(); + if (object != null) { + String userId = object.getString("userId"); + String userName = ""; + if (UserCache.getModel(userId) != null) { + userName = UserCache.getModel(userId).getUserName(); + } + object2.put("user", userName); + object2.put("dept", getDeptPath(userId)); + object2.put("date", object.getTimestamp("date")); + object2.put("desc", UtilString.isEmpty(object.getString("desc")) ? "" : object.getString("desc")); + object2.put("taskId", object.containsKey("taskId") ? object.getString("taskId") : ""); + } else { + object2.put("user", ""); + object2.put("dept", ""); + object2.put("date", ""); + object2.put("desc", ""); + object2.put("taskId", ""); + } + object2.put("id", model.getId()); + object2.put("name", model.getName()); + object2.put("version", model.getVersion()); + + // 获取路径 + StringBuilder sBuilder = new StringBuilder();// 名称组合 + Set idSets = new HashSet<>();// id记录,校验防止递归死循环 + sBuilder.append(model.getName()); + idSets.add(model.getId()); + getFilePath(model, sBuilder,idSets);// 递归获取当前文件名称路径 + object2.put("path", sBuilder.toString()); + result.add(object2); + } + return result; + } + + /** + * 获取文件名称全路径 + * @param model + * @return + */ + private void getFilePath(PALRepositoryModel model, StringBuilder sBuilder, Set idSets) { + if (model.getParentId().length() == 36) { + if (!idSets.contains(model.getParentId())) { + String parentId = model.getParentId(); + PALRepositoryModel parentModel = PALRepositoryCache.getCache().get(parentId); + if (parentModel != null) { + sBuilder.insert(0, parentModel.getName() + ">"); + idSets.add(parentModel.getId()); + getFilePath(parentModel, sBuilder, idSets); + } + } + } else { + sBuilder.insert(0, I18nRes.findValue(CoEConstant.APP_ID, model.getParentId()) + ">"); + } + } + + /** + * 打开流程地图 + * @param wsId + * @param orgId + * @param type + * @return + */ + public String openProcessMapPage(UserContext uc, String wsId, String orgId, String type) { + Map macroLibraries = getHomePage2(uc); + macroLibraries.put("wsId", wsId); + // 获取权限资产库列表 + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, "process"); + // List> wsList = getPermRepositoryVersionIdByUser(uc, roleId); + JSONArray ws = new JSONArray(); + if (wsList != null && wsList.size() > 0) { + for (int i = 0; i < wsList.size(); i++) { + JSONObject object = new JSONObject(); + object.put("id", wsList.get(i).get("wsId")); + object.put("text", wsList.get(i).get("wsName")); + ws.add(object); + } + } + macroLibraries.put("ws", ws); + // 在里面则返回名称,不在里面返回空 + macroLibraries.put("orgId", orgId); + // 获取单位列表 + JSONArray org = new JSONArray(); + List orgList = SDK.getORGAPI().getCompanys(); + if (orgList != null && orgList.size() > 0) { + for (int i = 0; i < orgList.size(); i++) { + if (orgList.get(i).isClosed()) { + continue; + } + JSONObject object = new JSONObject(); + object.put("id", orgList.get(i).getId()); + object.put("text", orgList.get(i).getName()); + org.add(object); + } + } + macroLibraries.put("org", org); + macroLibraries.put("type", type); + JSONObject object = getLogoImgPath(uc); + macroLibraries.put("logoImgPath", object.getString("src")); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.processmap.html", macroLibraries); + } + + /** + * 业务架构页面 + * @param me + * @param wsId + * @return + */ + public String openProcessMapWsPage(UserContext me, String wsId) { + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + Map macroLibraries = new HashMap<>(); + macroLibraries.put("sid", me.getSessionId()); + macroLibraries.put("uid", me.getUID()); + macroLibraries.put("wsId", wsId); + JSONArray firstLevel = new JSONArray(); + JSONObject secendLevel = new JSONObject(); + if (!UtilString.isEmpty(wsId)) { + @SuppressWarnings("unchecked") + List list = IteratorUtils.toList(PALRepositoryCache.getByPid(wsId, "process")); + list = filterPublisherData(list); + if (list != null && list.size() > 0) { + Collections.sort(list, new Comparator() { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + return o1.getOrderIndex() > o2.getOrderIndex() ? 1 : o1.getOrderIndex() < o2.getOrderIndex() ? -1 : 0; + } + }); + PALRepository dao = new PALRepository(); + Set idSet = dao.getRepositoryVersionIdListByPublishRole(roleId, "'" + wsId + "'", "process"); + Set relationAwsIdSet = getAwsOrgPermRepositoryByUser(_uc, "process", true); + if (relationAwsIdSet != null && relationAwsIdSet.size() > 0) { + for (String awsId : relationAwsIdSet) { + idSet.add(awsId); + } + } + for (PALRepositoryModel model : list) { + boolean flag = false; + if (model.isPublish() && idSet.contains(model.getVersionId())) { + flag = true; + } else { + Set ids = new HashSet<>(); + List subList = new ArrayList<>(); + PALRepositoryCache.getAllChildrenModelsByPid(wsId, model.getId(), subList, ids); + if (subList != null && subList.size() > 0) { + for (PALRepositoryModel subModel : subList) { + if (subModel.isPublish() && idSet.contains(subModel.getVersionId())) { + flag = true; + break; + } + } + } + } + if (flag) { + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("versionId", model.getVersionId()); + object.put("name", model.getName()); + object.put("canOpen", idSet.contains(model.getVersionId())); + object.put("isPublish", model.isPublish()); + object.put("method", model.getMethodId()); + firstLevel.add(object); + } + } + + for (int i = 0; i < firstLevel.size(); i++) { + JSONObject firstObject = firstLevel.getJSONObject(i); + getPublishAndRoleChildModel(wsId, idSet, firstObject.getString("versionId"), secendLevel); + } + } + } + macroLibraries.put("firstLevelData", firstLevel); + macroLibraries.put("secendLevelData", secendLevel); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.processmap.ws.html", macroLibraries); + } + + /** + * 获取子级节点 + * @param wsId + * @param filterSet + * @param version + * @param result + */ + private void getPublishAndRoleChildModel(String wsId, Set filterSet, String version, JSONObject result) { + List secendList = PALRepositoryCache.getAllSubModelsByPid(wsId, version); + secendList.sort((o1, o2)-> {return o1.getOrderIndex() > o2.getOrderIndex() ? 1 : o1.getOrderIndex() < o2.getOrderIndex() ? -1 : 0;}); + Set useVersionIds = new HashSet<>(); + List publishVersionIds = new ArrayList<>(); + JSONArray secendArr = new JSONArray(); + for (PALRepositoryModel model : secendList) { + if (model.isUse()) { + useVersionIds.add(model.getVersionId()); + } + if (model.isPublish()) { + publishVersionIds.add(model.getVersionId()); + } + } + for (String str : useVersionIds) { + if (!publishVersionIds.contains(str)) { + publishVersionIds.add(str); + } + } + for (String versionId : publishVersionIds) { + boolean flag = false; + PALRepositoryModel model = null;// = PALRepositoryCache.getCache().get(versionId); + List models = PALRepositoryCache.getByVersionId(wsId, versionId); + if (models != null && models.size() > 0) { + PALRepositoryModel temp = null; + for (PALRepositoryModel obj : models) { + if (obj.isPublish()) { + temp = obj; + break; + } + } + if (temp == null) { + for (PALRepositoryModel obj : models) { + if (obj.isUse()) { + temp = obj; + } + } + } + model = temp; + } + + if (model != null) { + flag = checkCanShow(wsId, filterSet, flag, model); + } + if (flag) { + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("versionId", model.getVersionId()); + object.put("name", model.getName()); + object.put("canOpen", filterSet.contains(model.getVersionId())); + object.put("child", checkChild(wsId, filterSet, false, model)); + object.put("isPublish", model.isPublish()); + secendArr.add(object); + } + } + result.put(version, secendArr); + } + + /** + * 判断是否有子流程并且有其权限 + * @param wsId + * @param filterSet + * @param flag + * @param model + * @return + */ + private boolean checkChild(String wsId, Set filterSet, boolean flag, PALRepositoryModel model) { + Set ids = new HashSet<>(); + List subList = new ArrayList<>(); + PALRepositoryCache.getAllChildrenModelsByPid(wsId, model.getId(), subList, ids); + if (subList != null && subList.size() > 0) { + for (PALRepositoryModel subModel : subList) { + if (subModel.isPublish() && filterSet.contains(subModel.getVersionId())) { + flag = true; + break; + } + } + } + return flag; + } + + /** + * 查看当前流程是否能显示 + * 判断条件:1.当前流程已发布且有权限;2.当前流程的所有子流程存在发布且其有权限查看 + * @param wsId + * @param filterSet + * @param flag + * @return + */ + private boolean checkCanShow(String wsId, Set filterSet, boolean flag, PALRepositoryModel model) { + if (model.isPublish() && filterSet.contains(model.getVersionId())) { + flag = true; + } else { + flag = checkChild(wsId, filterSet, flag, model); + } + return flag; + } + + /** + * 组织架构页面 + * @param me + * @param orgId + * @return + */ + public String openProcessMapOrgPage(UserContext me, String orgId) { + Map macroLibraries = new HashMap<>(); + macroLibraries.put("sid", me.getSessionId()); + macroLibraries.put("uid", me.getUID()); + macroLibraries.put("orgId", orgId); + JSONArray firstLevel = new JSONArray(); + JSONObject secendLevel = new JSONObject(); + if (!UtilString.isEmpty(orgId)) { + List list = SDK.getORGAPI().getDepartmentsByCompanyId(1, orgId); + if (list != null && list.size() > 0) { + // 获取单位下一级部门 + for (DepartmentModel model : list) { + if (model.isClosed()) { + continue; + } + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + boolean isExistSub = SDK.getORGAPI().isExistSubDepartment(model.getId()); + object.put("child", isExistSub); + firstLevel.add(object); + // 获取一级部门下的二级部门 + if (isExistSub) { + List subList = SDK.getORGAPI().getSubDepartments(model.getId()); + JSONArray subArray = new JSONArray(); + if (subList != null && subList.size() > 0) { + for (DepartmentModel subModel : subList) { + if (subModel.isClosed()) { + continue; + } + JSONObject object2 = new JSONObject(); + object2.put("id", subModel.getId()); + object2.put("name", subModel.getName()); + boolean isExistSub2 = SDK.getORGAPI().isExistSubDepartment(subModel.getId()); + object2.put("child", isExistSub2); + subArray.add(object2); + } + } + secendLevel.put(model.getId(), subArray); + } + } + + } + } + macroLibraries.put("firstLevelData", firstLevel); + macroLibraries.put("secendLevelData", secendLevel); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.processmap.org.html", macroLibraries); + } + + /** + * 业务架构展开 + * @param me + * @param id + * @param wsId + * @return + */ + public String expendProcessMapWsData(UserContext me, String id, String wsId) { + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model == null) { + throw new AWSException("该流程不存在,请刷新重试"); + } + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + PALRepository dao = new PALRepository(); + Set idSet = dao.getRepositoryVersionIdListByPublishRole(roleId, "'" + wsId + "'", "process"); + Set relationAwsIdSet = getAwsOrgPermRepositoryByUser(_uc, "process", true); + if (relationAwsIdSet != null && relationAwsIdSet.size() > 0) { + for (String awsId : relationAwsIdSet) { + idSet.add(awsId); + } + } + JSONObject nextLevel = new JSONObject(); + getPublishAndRoleChildModel(wsId, idSet, model.getVersionId(), nextLevel); + ro.put("data", nextLevel.get(model.getVersionId())); + return ro.toString(); + } + + /** + * 打开文件时的权限和类型校验 + * @param me + * @param id + * @param wsId + * @return + */ + public String openProcessMapWsDataCheck(UserContext me, String id, String wsId) { + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model == null) { + throw new AWSException("该流程不存在,请刷新重试"); + } + if (UtilString.isEmpty(wsId)) { + wsId = model.getWsId(); + } + String status = "ok"; + if ("default".equals(model.getMethodId())) { + status = "typeError"; + } + if (!model.isPublish()) { + status = "notPublish"; + } + if (!"ok".equals(status)) {// 避免后续查询 + ro.put("status", status); + return ro.toString(); + } + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + PALRepository dao = new PALRepository(); + Set idSet = dao.getRepositoryVersionIdListByPublishRole(roleId, "'" + wsId + "'", "process"); + Set relationAwsIdSet = getAwsOrgPermRepositoryByUser(_uc, "process", true); + if (relationAwsIdSet != null && relationAwsIdSet.size() > 0) { + for (String awsId : relationAwsIdSet) { + idSet.add(awsId); + } + } + if (!idSet.contains(model.getVersionId())) { + status = "noPerm"; + } + ro.put("status", status); + return ro.toString(); + } + + /** + * 组织架构展开 + * @param me + * @param id 部门id + * @param orgId 单位id + * @return + */ + + public String expendProcessMapOrgData(UserContext me, String id, String orgId) { + ResponseObject ro = ResponseObject.newOkResponse(); + DepartmentModel model = SDK.getORGAPI().getDepartmentById(id); + if (model == null) { + throw new AWSException("该部门不存在,请刷新重试"); + } + JSONArray data = new JSONArray(); + List list = SDK.getORGAPI().getSubDepartments(id); + if (list != null && list.size() > 0) { + for (DepartmentModel subModel : list) { + if (subModel.isClosed()) { + continue; + } + JSONObject object = new JSONObject(); + object.put("id", subModel.getId()); + object.put("name", subModel.getName()); + boolean isExistSub = SDK.getORGAPI().isExistSubDepartment(subModel.getId()); + object.put("child", isExistSub); + data.add(object); + } + } + ro.put("data", data); + return ro.toString(); + } + + /** + * 查询组织架构中部门流程 + * @param me + * @param deptId + * @return + */ + public String openProcessMapOrgDeptDialog(UserContext me, String deptId) { + Map macroLibraries = new HashMap<>(); + macroLibraries.put("sid", me.getSessionId()); + macroLibraries.put("uid", me.getUID()); + macroLibraries.put("deptId", deptId); + DepartmentModel model = SDK.getORGAPI().getDepartmentById(deptId); + JSONArray data = new JSONArray(); + String deptName = ""; + if(model != null) { + deptName = model.getName(); + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + PALRepository dao = new PALRepository(); + // List list = dao.getRepositoryListByPublishRole(roleId, null, "process", deptId, "default"); + List list = dao.getRepositoryListByPublishRole(roleId, null, "process", null, "default"); + // 查询关联了当前部门的已发布流程 + Set relationDeptIds = getAwsOrgPermRepositoryByDept(_uc, "process", deptId, true); + if (!isEmpty(list)) { + for (PALRepositoryModel pModel : list) { + if (deptId.equals(pModel.getDutyDept()) || relationDeptIds.contains(pModel.getId())) { + JSONObject object = new JSONObject(); + object.put("id", pModel.getId()); + object.put("name", pModel.getName()); + object.put("method", pModel.getMethodId()); + data.add(object); + } + } + } + } + macroLibraries.put("deptName", deptName); + macroLibraries.put("data", data); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.sso.processmap.org.dialog.html", macroLibraries); + } + + // 获取logo图片路径 + private JSONObject getLogoImgPath(UserContext uc) { + JSONObject logo = new JSONObject(); + DCContext logoDcContext = null; + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, "portalTheme"); + if (dcProfile != null) { + logoDcContext = new DCContext(uc, dcProfile, "portal", "logo"); + } + boolean flag1 = false; + if (logoDcContext != null) { + File file = new File(logoDcContext.getPath()); + if (file.exists()) { + File [] files = file.listFiles(); + if (files != null) { + if (files.length > 0) { + for (File file2 : files) { + String src = new DCContext(uc, dcProfile, CoEConstant.APP_ID, "portal", "logo", file2.getName()).getDownloadURL(); + logo.put("src", src); + logo.put("name", file2.getName()); + flag1 = true; + break; + } + } + } + } + } + if (!flag1) { + // 默认PALlogo + logo.put("src", "../apps/"+ CoEConstant.APP_ID +"/img/logo/portal_logo.png"); + logo.put("name", "portal_logo.png"); + } + return logo; + } + + /** + * 轮播图 + * @param uc + * @return + */ + public String queryBannerData(UserContext uc) { + Map result = new HashMap(); + result.put("sid", uc.getSessionId()); + result.put("uid", uc.getUID()); + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, "portalTheme"); + DCContext bannerDcContext = null; + if (dcProfile != null) { + bannerDcContext = new DCContext(_uc, dcProfile, "portal", "banner"); + } + // 轮播图设置 + JSONArray pictures = new JSONArray(); + if (bannerDcContext != null) { + File file = new File(bannerDcContext.getPath()); + if (file.exists()) { + File [] files = file.listFiles(); + if (files != null) { + // 按照名称排序 + List fileList = Arrays.asList(files); + Collections.sort(fileList, new Comparator() { + @Override + public int compare(File o1, File o2) { + if (o1.isDirectory() && o2.isFile()) + return -1; + if (o1.isFile() && o2.isDirectory()) + return 1; + return o1.getName().compareTo(o2.getName()); + } + }); + for (int i = 0; i < fileList.size(); i++) { + File file2 = files[i]; + String src = new DCContext(_uc, dcProfile, CoEConstant.APP_ID, "portal", "banner", file2.getName()).getDownloadURL(); + JSONObject object = new JSONObject(); + object.put("src", src); + object.put("name", file2.getName()); + pictures.add(object); + } + } + } + } + if (pictures.isEmpty()) { + JSONObject object = new JSONObject(); + object.put("src", "../apps/"+ CoEConstant.APP_ID +"/img/portal_banner.jpg"); + object.put("name", "portal_banner"); + pictures.add(object); + } + result.put("bannerImgs", pictures); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.banner.html", result); + } + + /*********************永辉接口start***************************/ + + // 查询发布信息,拼接结果json + private JSONArray assembleData2(List list) { + PublishListHistory pHistory = new PublishListHistory(); + JSONArray result = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + PALRepositoryModel model = list.get(i); + JSONObject object = pHistory.getLastPublishByModelId(model.getId()); + JSONObject object2 = new JSONObject(); + if (object != null) { + String userId = object.getString("userId"); + String userName = ""; + if (UserCache.getModel(userId) != null) { + userName = UserCache.getModel(userId).getUserName(); + } + object2.put("user", userName); + object2.put("departmentPath", getDeptPath(userId)); + object2.put("publishDate", UtilDate.datetimeFormat(object.getTimestamp("date"))); + object2.put("publishDesc", object.getString("desc")); + } else { + object2.put("user", ""); + object2.put("departmentPath", ""); + object2.put("publishDate", ""); + object2.put("publishDesc", ""); + } + object2.put("id", model.getId()); + object2.put("name", model.getName()); + object2.put("version", VersionUtil.getVersionStrV(model.getVersion())); + object2.put("method", model.getMethodId()); + object2.put("category", model.getMethodCategory()); + + // 获取路径 + StringBuilder sBuilder = new StringBuilder();// 名称组合 + Set idSets = new HashSet<>();// id记录,校验防止递归死循环 + sBuilder.append(model.getName()); + idSets.add(model.getId()); + getFilePath(model, sBuilder,idSets);// 递归获取当前文件名称路径 + object2.put("path", sBuilder.toString()); + result.add(object2); + } + return result; + } + + /** + * 获取所有文件 + * @param uc + * @param wsId + * @param category + * @param type 已发布或者全部 + * @return + */ + public String queryPublishRepositoryDataJson(UserContext uc, String wsId, String category, String type) { + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + String wsIdsql = "'" + wsId + "'"; + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepository dao = new PALRepository(); + List list = null; + if (type == null || "publish".equals(type)) { + list = dao.getRepositoryListByPublishRole(wsIdsql, roleId, null, category, true, false); + } else { + list = dao.getRepositoryListByPublishRole(wsIdsql, roleId, null, category, false, true); + } + if (list == null) { + list = new ArrayList<>(); + } + JSONArray result = assembleData2(list); + ro.setData(result); + return ro.toString(); + } + + /** + * 获取所有已发布的文件 + * @param wsId + * @return + */ + public String queryPublishRepositoryDataJson(UserContext uc, String wsId, String category) { + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + String wsIdsql = "'" + wsId + "'"; + ResponseObject ro = ResponseObject.newOkResponse(); + PALRepository dao = new PALRepository(); + List list = dao.getRepositoryListByPublishRole(wsIdsql, roleId, null, category); + if (list == null) { + list = new ArrayList<>(); + } + Set idSet = new HashSet<>(); + for (PALRepositoryModel model : list) { + idSet.add(model.getId()); + } + // 添加关联aws组织的流程进行合并 + boolean flag = false; + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + if (awsProcessIds != null && awsProcessIds.size() > 0) { + for (String processId : awsProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(processId); + if (model != null && wsIdsql.indexOf(model.getWsId()) > -1 && !idSet.contains(model.getId())) { + list.add(model); + idSet.add(model.getId()); + flag = true; + } + } + } + if (flag) {// 合并过数据则需要重新排序 + // 排序 + Collections.sort(list, new MyComparator()); + } + JSONArray result = assembleData2(list); + ro.setData(result); + return ro.toString(); + } + + /** + * 获取所有有权限的资产库 + * @return + */ + public String queryPermWorkspaceDataJson(UserContext uc) { + ResponseObject ro = ResponseObject.newOkResponse(); + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + List> wsList = getPalAndAwsPermRepositoryVersionIdByUser(uc, roleId, null); + JSONArray ws = new JSONArray(); + if (wsList != null && wsList.size() > 0) { + for (int i = 0; i < wsList.size(); i++) { + JSONObject object = new JSONObject(); + object.put("wsId", wsList.get(i).get("wsId")); + object.put("wsName", wsList.get(i).get("wsName")); + ws.add(object); + } + } + ro.setData(ws); + return ro.toString(); + } + + /** + * 按照创建时间倒序排序 + * + */ + private class CreateDateComparator implements Comparator { + + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + Timestamp p1 = o1.getCreateDate(); + Timestamp p2 = o2.getCreateDate(); + if (p1 != null && p2 != null) { + if (!p1.equals(p2)) { + return p2.compareTo(p1); + } + } + int level1 = o1.getLevel(); + int level2 = o2.getLevel(); + if (level1 != level2) { + return level1 - level2; + } + int order1 = o1.getOrderIndex(); + int order2 = o2.getOrderIndex(); + return order1 - order2; + } + + } + + /** + * 获取发布动态 + * @param wsId + * @return + */ + public String queryDynamicHistoryDataJson(UserContext uc, String wsId, String type) { + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + String wsIdsql = "'" + wsId + "'"; + ResponseObject ro = ResponseObject.newOkResponse(); + + if (type == null || "publish".equals(type)) {// 获取已发布流程 + + } else {// 按照创建时间倒序获取所有流程 + JSONArray result = new JSONArray(); + List list = new ArrayList<>(); + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Iterator iterator = PALRepositoryCache.getByWsId(wsId); + while (iterator.hasNext()) { + PALRepositoryModel model = iterator.next(); + if (palVersionIds.contains(model.getVersionId())) { + list.add(model); + } + } + // 按照时间倒序,名称升序排序 + Collections.sort(list, new CreateDateComparator()); + for (PALRepositoryModel palModel : list) { + JSONObject object2 = new JSONObject(); + String userName = ""; + String userId = palModel.getCreateUser(); + if (!UtilString.isEmpty(userId) && UserCache.getModel(userId) != null) { + userName = UserCache.getModel(userId).getUserName(); + } + object2.put("id", palModel.getId()); + object2.put("version", VersionUtil.getVersionStrV(palModel.getVersion())); + object2.put("user", userName); + object2.put("name", palModel.getName()); + object2.put("createDate", UtilDate.datetimeFormat(palModel.getCreateDate())); + object2.put("isPublish", palModel.isPublish() ? "1" : "0"); + object2.put("method", palModel.getMethodId()); + object2.put("category", palModel.getMethodCategory()); + // 获取发布类型名称 + String categoryName = ""; + if (palModel.getLevel() <= 2) { + categoryName = palModel.getName(); + } else { + PALRepositoryModel model = palModel; + while (true) { + String pid = model.getParentId(); + PALRepositoryModel parentModel = PALRepositoryCache.getCache().get(pid); + if (parentModel == null) { + break; + } else { + if (parentModel.getLevel() <= 2) { + categoryName = parentModel.getName(); + break; + } + } + model = parentModel; + } + } + object2.put("categoryName", categoryName); + result.add(object2); + } + ro.setData(result); + return ro.toString(); + } + + PublishListHistory dao = new PublishListHistory(); + List modelList = dao.getPublishListHistoryByRole(roleId, null, wsIdsql, null); + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + palProcessIds.add(model.getId()); + } + } + } + + // 过滤最终结果 + List list = new ArrayList<>(); + for (JSONObject object : modelList) { + String repositoryId = object.getString("repositoryId"); + if (palProcessIds.contains(repositoryId)) { + list.add(object); + } + } + + JSONArray result = new JSONArray(); + for (JSONObject object : list) { + JSONObject object2 = new JSONObject(); + String repositoryId = object.getString("repositoryId"); + PALRepositoryModel palModel = PALRepositoryCache.getCache().get(repositoryId); + object2.put("id", palModel.getId()); + object2.put("version", VersionUtil.getVersionStrV(palModel.getVersion())); + String userName = ""; + if (UserCache.getModel(object.getString("userId")) != null) { + userName = UserCache.getModel(object.getString("userId")).getUserName(); + } + + String actionType = object.getString("actionType"); + String intro = ""; + switch (actionType) { + case "N": + intro = "新发布"; + break; + case "C": + intro = "变更"; + break; + default:// S + intro = "停用"; + break; + } + object2.put("name", palModel.getName() + "[" + intro + "]"); + object2.put("user", userName); + object2.put("publishDate", UtilDate.datetimeFormat(object.getTimestamp("publishDate"))); + object2.put("publishDesc", object.getString("publishDesc")); + object2.put("isPublish", palModel.isPublish() ? "1" : "0"); + object2.put("method", palModel.getMethodId()); + object2.put("category", palModel.getMethodCategory()); + // 获取发布类型名称 + String categoryName = ""; + if (palModel.getLevel() <= 2) { + categoryName = palModel.getName(); + } else { + PALRepositoryModel model = palModel; + while (true) { + String pid = model.getParentId(); + PALRepositoryModel parentModel = PALRepositoryCache.getCache().get(pid); + if (parentModel == null) { + break; + } else { + if (parentModel.getLevel() <= 2) { + categoryName = parentModel.getName(); + break; + } + } + model = parentModel; + } + } + object2.put("categoryName", categoryName); + result.add(object2); + } + ro.setData(result); + return ro.toString(); + } + + /** + * 获取发布动态(更多) + * @param wsId + * @return + */ + public String queryDynamicHistoryMoreDataJson(UserContext uc, String wsId, String type) { + JSONObject param = getXPagesBasicParam(uc, null); + String roleId = param.getString("roleId"); + String wsIdsql = "'" + wsId + "'"; + + ResponseObject ro = ResponseObject.newOkResponse(); + + if (type == null || "publish".equals(type)) {// 获取已发布流程 + + } else {// 按照创建时间倒序获取所有流程 + JSONArray result = new JSONArray(); + List list = new ArrayList<>(); + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Iterator iterator = PALRepositoryCache.getByWsId(wsId); + while (iterator.hasNext()) { + PALRepositoryModel model = iterator.next(); + if (palVersionIds.contains(model.getVersionId())) { + list.add(model); + } + } + // 按照时间倒序,名称升序排序 + Collections.sort(list, new CreateDateComparator()); + for (PALRepositoryModel palModel : list) { + JSONObject object2 = new JSONObject(); + object2.put("id", palModel.getId()); + object2.put("version", VersionUtil.getVersionStrV(palModel.getVersion())); + String userName = ""; + String userId = palModel.getCreateUser(); + if (!UtilString.isEmpty(userId) && UserCache.getModel(userId) != null) { + userName = UserCache.getModel(userId).getUserName(); + } + object2.put("name", palModel.getName()); + object2.put("user", userName); + object2.put("departmentPath", getDeptPath(palModel.getCreateUser())); + object2.put("createDate", UtilDate.datetimeFormat(palModel.getCreateDate())); + object2.put("isPublish", palModel.isPublish() ? "1" : "0"); + object2.put("method", palModel.getMethodId()); + object2.put("category", palModel.getMethodCategory()); + + // 获取路径 + StringBuilder sBuilder = new StringBuilder();// 名称组合 + Set idSets = new HashSet<>();// id记录,校验防止递归死循环 + sBuilder.append(palModel.getName()); + idSets.add(palModel.getId()); + getFilePath(palModel, sBuilder,idSets);// 递归获取当前文件名称路径 + object2.put("path", sBuilder.toString()); + result.add(object2); + } + ro.setData(result); + return ro.toString(); + } + + PublishListHistory dao = new PublishListHistory(); + List modelList = dao.getPublishListHistoryByRole(roleId, null, wsIdsql, null); + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + palProcessIds.add(model.getId()); + } + } + } + + // 过滤最终结果 + List list = new ArrayList<>(); + for (JSONObject object : modelList) { + String repositoryId = object.getString("repositoryId"); + if (palProcessIds.contains(repositoryId)) { + list.add(object); + } + } + + JSONArray result = new JSONArray(); + for (JSONObject object : list) { + JSONObject object2 = new JSONObject(); + String repositoryId = object.getString("repositoryId"); + PALRepositoryModel palModel = PALRepositoryCache.getCache().get(repositoryId); + object2.put("id", palModel.getId()); + object2.put("version",VersionUtil.getVersionStrV(palModel.getVersion())); + String userName = ""; + if (UserCache.getModel(object.getString("userId")) != null) { + userName = UserCache.getModel(object.getString("userId")).getUserName(); + } + + String actionType = object.getString("actionType"); + String intro = ""; + switch (actionType) { + case "N": + intro = "新发布"; + break; + case "C": + intro = "变更"; + break; + default:// S + intro = "停用"; + break; + } + object2.put("name", palModel.getName() + "[" + intro + "]"); + object2.put("user", userName); + object2.put("departmentPath", getDeptPath(object.getString("userId"))); + object2.put("publishDate", UtilDate.datetimeFormat(object.getTimestamp("publishDate"))); + object2.put("publishDesc", object.getString("publishDesc")); + object2.put("isPublish", palModel.isPublish() ? "1" : "0"); + object2.put("method", palModel.getMethodId()); + object2.put("category", palModel.getMethodCategory()); + + // 获取路径 + StringBuilder sBuilder = new StringBuilder();// 名称组合 + Set idSets = new HashSet<>();// id记录,校验防止递归死循环 + sBuilder.append(palModel.getName()); + idSets.add(palModel.getId()); + getFilePath(palModel, sBuilder,idSets);// 递归获取当前文件名称路径 + object2.put("path", sBuilder.toString()); + result.add(object2); + } + ro.setData(result); + return ro.toString(); + } + + /** + * 根据类别获取权限下的发布流程 + * @param me + * @param type publish:获取当前状态为已发布且有权限的文件 stop: 获取曾经发布过但是当前是未发布状态(使用中)的文件 recentView:按照流程点击量倒序获取当前状态为已发布的文件(类似高频流程) + * @param wsId + * @return + */ + public String queryPublishRepositoryDataJsonByType(UserContext me, String type, String wsId) { + switch (type) { + case "publish": + // 获取已发布流程 + return queryPublishRepositoryDataJson(me, wsId, "process"); + case "stop": + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + PublishListHistory history = new PublishListHistory(); + Set publishHistorySet = history.getPublishDataByActiontype("S", wsId); + // 获取权限下的模型id + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + palProcessIds.add(model.getId()); + } + } + } + // 获取关联AWS组织的版本ID且当前为未发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, null, false); + // 整合所有权限 + palProcessIds.addAll(awsProcessIds); + List list = new ArrayList<>(); + Iterator iterator = PALRepositoryCache.getByWsId(wsId); + while (iterator.hasNext()) { + PALRepositoryModel model = iterator.next(); + if (!model.isPublish() && "process".equals(model.getMethodCategory()) && publishHistorySet.contains(model.getId()) && palProcessIds.contains(model.getId())) {// 未发布&&已停用&&有权限 + list.add(model); + } + } + // 排序 + Collections.sort(list, new MyComparator()); + JSONArray data = assembleData2(list); + ResponseObject r2 = ResponseObject.newOkResponse(); + r2.setData(data); + return r2.toString(); + default:// recentView + List tempList = new ArrayList<>(); + PublishFrequencyDao frequencyDao = new PublishFrequencyDao(); + List frequencyModels = frequencyDao.getDataOrderByCount(wsId); + if (frequencyModels == null || frequencyModels.size() == 0) { + ResponseObject r = ResponseObject.newOkResponse(); + r.setData(tempList); + return r.toString(); + } + Map map = new HashMap<>(); + for (PublishFrequencyModel model : frequencyModels) { + map.put(model.getPlversionId(), model.getCount()); + } + String result = queryPublishRepositoryDataJson(me, wsId, "process"); + JSONObject ro = JSONObject.parseObject(result); + JSONArray array = ro.getJSONArray("data"); + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + String id = object.getString("id"); + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model!= null) { + String versionId = model.getVersionId(); + if (map.containsKey(versionId)) { + object.put("viewCount", map.get(versionId)); + tempList.add(object); + } + } + } + // 按照访问量降序排序 + Collections.sort(tempList, new CountComparator()); + ResponseObject r = ResponseObject.newOkResponse(); + r.setData(tempList); + return r.toString(); + } + } + + private class CountComparator implements Comparator { + @Override + public int compare(JSONObject o1, JSONObject o2) { + Integer count1 = o1.getInteger("viewCount"); + Integer count2 = o2.getInteger("viewCount"); + return count2 - count1; + } + } + + /** + * 获取所有有权限的部门列表,部门列表来源于所有具有权限的流程的责任部门 + * 已发布 + * @param me + * @param wsId + * @return + */ + public String queryAwsDepartmentDataJson(UserContext me, String wsId) { + String category = "process"; + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + if (model.isPublish() && model.getMethodCategory().equals(category)) { + palProcessIds.add(model.getId()); + } + } + } + } + // 获取关联AWS组织的版本ID且当前为已发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + // 整合所有权限 + palProcessIds.addAll(awsProcessIds); + + // 获取所有部门ID + Set deptIds = new HashSet<>(); + for (String id : palProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null && model.getWsId().equals(wsId)) { + // 责任部门 + String deptId = model.getDutyDept(); + if (!UtilString.isEmpty(deptId)) { + deptIds.add(deptId); + } + } + } + List list = new ArrayList<>(); + for (String deptId : deptIds) { + JSONObject object = new JSONObject(); + DepartmentModel dModel = SDK.getORGAPI().getDepartmentById(deptId); + if (dModel != null) { + // 获取单位 + CompanyModel cModel = SDK.getORGAPI().getCompanyById(dModel.getCompanyId()); + if (cModel != null) { + object.put("id", dModel.getId()); + object.put("departmentId", dModel.getId()); + object.put("departmentName", dModel.getName()); + object.put("departmentLayer", dModel.getLayer()); + object.put("departmentOrderIndex", dModel.getOrderIndex()); + object.put("departmentClosed", dModel.isClosed()); + object.put("companyId", dModel.getCompanyId()); + object.put("companyName", cModel.getName()); + object.put("companyOrderIndex", cModel.getOrderIndex()); + object.put("companyClosed", cModel.isClosed()); + list.add(object); + } + } + } + // 排序,按照单位部门层级和顺序排序 + Collections.sort(list, new DepartmentComparator()); + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(list); + return ro.toString(); + } + + // 部门排序 + private class DepartmentComparator implements Comparator{ + @Override + public int compare(JSONObject o1, JSONObject o2) { + int cOrder1 = o1.getIntValue("companyOrderIndex"); + int cOrder2 = o2.getIntValue("companyOrderIndex"); + if (cOrder1 != cOrder2) { + return cOrder1 - cOrder2; + } + int dLayer1 = o1.getIntValue("departmentLayer"); + int dLayer2 = o2.getIntValue("departmentLayer"); + if (dLayer1 != dLayer2) { + return dLayer1 - dLayer2; + } + int dOrder1 = o1.getIntValue("departmentOrderIndex"); + int dOrder2 = o2.getIntValue("departmentOrderIndex"); + return dOrder1 - dOrder2; + } + + } + + /** + * 获取当前部门的流程数据(责任部门)和当前部门下具有权限的子部门列表 + * @param me + * @param wsId + * @param departmentId + * @return + */ + public String queryPublishedProcessAndSubDepartment(UserContext me, String wsId, String departmentId) { + JSONObject result = new JSONObject(); + // 获取有权限的已发布流程 + String category = "process"; + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + // 过滤当前责任部门的流程 + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + if (model.isPublish() && model.getMethodCategory().equals(category)) { + palProcessIds.add(model.getId()); + } + } + } + } + // 获取关联AWS组织的版本ID且当前为已发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + // 整合所有权限id + palProcessIds.addAll(awsProcessIds); + List list = new ArrayList<>(); + Set deptIds = new HashSet<>(); + for (String id : palProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null && model.getWsId().equals(wsId)) { + // 责任部门 + String deptId = model.getDutyDept(); + if (!UtilString.isEmpty(deptId)) { + deptIds.add(deptId); + if (deptId.equals(departmentId)) { + list.add(model); + } + } + } + } + Collections.sort(list, new MyComparator()); + JSONArray repositoryArr = new JSONArray(); + for (PALRepositoryModel model : list) { + // "子部门列表(部门id,部门名称); + // 所有选择了该部门作为责任部门的流程文件列表(流程id,流程名称,是否有附件、附件Id,附件名称、附件链接、流程地图图片)" + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("version",VersionUtil.getVersionStrV(model.getVersion())); + object.put("hasFile", false); + object.put("method", model.getMethodId()); + object.put("category", model.getMethodCategory()); + // 附件 + JSONArray file = new JSONArray(); + StringBuffer sqlWhere = new StringBuffer(); + sqlWhere.append(" and PALREPOSITORYID ='").append(model.getId()).append("' and FILETYPE='f'"); + UpFileDao upFileDao = new UpFileDao(); + List search = upFileDao.search(sqlWhere.toString()); + if (search != null && search.size() > 0) { + object.put("hasFile", true); + for (UpfileModel upfileModel : search) { + JSONObject fileObject = new JSONObject(); + fileObject.put("id", upfileModel.getUuid()); + fileObject.put("name", upfileModel.getFileName()); + String downloadUrl = ""; + DCContext dcContext = null; + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + if (dcProfile != null) { + dcContext = new DCContext(me, dcProfile, CoEConstant.APP_ID, "file",upfileModel.getPl_uuid(), upfileModel.getFileName()); + } + if (dcContext != null) { + downloadUrl = dcContext.getDownloadURL() + "&isInline=false"; + } + fileObject.put("url", downloadUrl); + file.add(fileObject); + } + } + object.put("file", file); + // 流程图片 + String imgSrc = ""; + String path = model.getFilePath(); + if (!UtilString.isEmpty(path)) { + UtilFile utilFile = new UtilFile(path + "/" + model.getId() + ".small.png"); + if (utilFile.exists()) { + byte[] base64Bytes = Base64.encode(utilFile.readBytes()); + imgSrc = "data:image/png;base64," + new String(base64Bytes); + } + } + object.put("imgSrc", imgSrc); + repositoryArr.add(object); + } + result.put("process", repositoryArr); + // 获取子部门列表 + List deptList = new ArrayList<>(); + getPermDepartment(deptList, deptIds, departmentId);// 获取子部门列表 + // 部门排序 + JSONArray deptArr = new JSONArray(); + for (DepartmentModel dept : deptList) { + JSONObject deptObj = new JSONObject(); + deptObj.put("id", dept.getId()); + deptObj.put("departmentName", dept.getName()); + deptArr.add(deptObj); + } + result.put("department", deptArr); + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(result); + return ro.toString(); + } + + // 获取所有符合条件的子部门 + private void getPermDepartment(List list, Set deptIds, String parentId) { + // 获取子部门列表 + List subDeptList = SDK.getORGAPI().getSubDepartments(parentId); + if (!isEmpty(subDeptList)) { + for (DepartmentModel model : subDeptList) { + if (deptIds.contains(model.getId())) { + list.add(model); + } else { + getPermDepartment(list, deptIds, model.getId()); + } + } + } + } + + // 获取子流程列表 + public String queryPublishProcessByParent(UserContext me, String id, String type) { + // 获取有权限的已发布流程 + String category = "process"; + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + // 过滤当前责任部门的流程 + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + if (type == null || "publish".equals(type)) {// 获取已发布流程 + if(model.isPublish() && model.getMethodCategory().equals(category)) { + palProcessIds.add(model.getId()); + } + } else {// 获取当前使用中流程,不区分状态 + if(model.isUse() && model.getMethodCategory().equals(category)) { + palProcessIds.add(model.getId()); + } + } + } + } + } + + // 获取当前流程信息和子流程 + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model == null) { + throw new AWSException("查找失败 uuid: " + id ); + } + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("version", VersionUtil.getVersionStrV(model.getVersion())); + object.put("hasChild", false); + object.put("childData", new JSONArray()); + object.put("method", model.getMethodId()); + object.put("category", model.getMethodCategory()); + object.put("level", model.getLevel()); + object.put("isPublish", model.isPublish()); + + // 获取子流程列表 + List subList = new ArrayList<>(); + getPermSubPalRepository(subList, palProcessIds, model.getId()); + if (!isEmpty(subList)) { + object.put("hasChild", true); + // 获取附件列表,获取流程图片 + JSONArray subArr = new JSONArray(); + for (PALRepositoryModel subModel : subList) { + JSONObject subObj = new JSONObject(); + subObj.put("id", subModel.getId()); + subObj.put("name", subModel.getName()); + subObj.put("version",VersionUtil.getVersionStrV(subModel.getVersion())); + subObj.put("hasFile", false); + subObj.put("method", subModel.getMethodId()); + subObj.put("category", subModel.getMethodCategory()); + subObj.put("level", subModel.getLevel()); + subObj.put("isPublish", subModel.isPublish()); + // 附件 + JSONArray file = new JSONArray(); + StringBuffer sqlWhere = new StringBuffer(); + sqlWhere.append(" and PALREPOSITORYID ='").append(subModel.getId()).append("' and FILETYPE='f'"); + UpFileDao upFileDao = new UpFileDao(); + List search = upFileDao.search(sqlWhere.toString()); + if (search != null && search.size() > 0) { + subObj.put("hasFile", true); + for (UpfileModel upfileModel : search) { + JSONObject fileObject = new JSONObject(); + fileObject.put("id", upfileModel.getUuid()); + fileObject.put("name", upfileModel.getFileName()); + String downloadUrl = ""; + DCContext dcContext = null; + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + if (dcProfile != null) { + dcContext = new DCContext(me, dcProfile, CoEConstant.APP_ID, "file",upfileModel.getPl_uuid(), upfileModel.getFileName()); + } + if (dcContext != null) { + downloadUrl = dcContext.getDownloadURL() + "&isInline=false"; + } + fileObject.put("url", downloadUrl); + file.add(fileObject); + } + } + subObj.put("file", file); + // 流程图片 + String imgSrc = ""; + String path = subModel.getFilePath(); + if (!UtilString.isEmpty(path)) { + UtilFile utilFile = new UtilFile(path + "/" + subModel.getId() + ".small.png"); + if (utilFile.exists()) { + byte[] base64Bytes = Base64.encode(utilFile.readBytes()); + imgSrc = "data:image/png;base64," + new String(base64Bytes); + } + } + subObj.put("imgSrc", imgSrc); + subArr.add(subObj); + } + object.put("childData", subArr); + } + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(object); + return ro.toString(); + } + + private void getPermSubPalRepository(List list, Set palProcessIds, String pid) { + // 获取子流程 + PALRepositoryModel model = PALRepositoryCache.getCache().get(pid); + if (model != null) { + List subList = PALRepositoryCache.getAllSubModelsByPid(model.getWsId(), model.getId()); + if (!isEmpty(subList)) { + // 排序 + Collections.sort(subList, new Comparator() { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + int level1 = o1.getLevel(); + int level2 = o2.getLevel(); + if (level1 != level2) { + return level1 - level2; + } + int orderIndex1 = o1.getOrderIndex(); + int orderIndex2 = o2.getOrderIndex(); + return orderIndex1 - orderIndex2; + } + }); + for (PALRepositoryModel subModel : subList) { + if (palProcessIds.contains(subModel.getId())) { + list.add(subModel); + } else { + getPermSubPalRepository(list, palProcessIds, subModel.getId()); + } + } + } + } + } + + /** + * 打开流程 + * @param me + * @param uuid + * @return + */ + public String openPublishRepository(UserContext me, String uuid, String type) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(uuid); + if (model != null) { + if ("default".equals(model.getMethodId())) { + throw new AWSException("当前文件类型不支持打开"); + } + } + if (type == null || "publish".equals(type)) {// 获取已发布流程 + return PALRepositoryQueryAPIManager.getInstance().getPublishPortalHtml(me, uuid, null); + } else {// 不再校验是否已发布 + return PALRepositoryQueryAPIManager.getInstance().getPublishPortalHtml(me, uuid, null, false); + } + } + + /** + * 查找二级流程 + * @param me + * @param wsId + * @param type all:所有当前正在使用状态中的模型,包括发布和停用 publish:已发布模型 + * @return + */ + public String querySecondLevelRepositoryDataJson(UserContext me, String wsId, String type) { + JSONArray result = new JSONArray(); + // 暂时不处理权限,取所有二级流程类文件 + List firstLevelModels = PALRepositoryCache.getAllSubModelsByPid(wsId, "process"); + if (!isEmpty(firstLevelModels)) { + Set versionIds = new HashSet<>(); + for (PALRepositoryModel model : firstLevelModels) { + if (!versionIds.contains(model.getVersionId())) { + // 获取第二级流程 + List secendLevelModels = PALRepositoryCache.getAllSubModelsByPid(wsId, model.getId()); + if (!isEmpty(secendLevelModels)) { + if (type == null || "publish".equals(type)) {// 获取已发布流程 + for (PALRepositoryModel sModel : secendLevelModels) { + if (sModel.isPublish()) { + JSONObject object = new JSONObject(); + object.put("id", sModel.getId()); + object.put("name", sModel.getName()); + object.put("level", sModel.getLevel()); + object.put("parentId", sModel.getParentId()); + object.put("method", sModel.getMethodId()); + object.put("category", sModel.getMethodCategory()); + object.put("parentName", model.getName()); + object.put("isPublish", model.isPublish()); + result.add(object); + } + } + } else {// 获取当前使用中流程,不区分状态 + for (PALRepositoryModel sModel : secendLevelModels) { + if (sModel.isUse()) { + JSONObject object = new JSONObject(); + object.put("id", sModel.getId()); + object.put("name", sModel.getName()); + object.put("level", sModel.getLevel()); + object.put("parentId", sModel.getParentId()); + object.put("method", sModel.getMethodId()); + object.put("category", sModel.getMethodCategory()); + object.put("parentName", model.getName()); + object.put("isPublish", model.isPublish()); + result.add(object); + } + } + } + } + versionIds.add(model.getVersionId()); + } + } + } + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(result); + return ro.toString(); + } + + /** + * 查找三级流程(已发布和未发布) + * @param me + * @param wsId + * @param type all:所有当前正在使用状态中的模型,包括发布和停用 publish:已发布模型 + * @return + */ + public String queryThirdLevelRepositoryDataJson(UserContext me, String wsId, String type) { + JSONArray result = new JSONArray(); + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(result); + Set versionIds = new HashSet<>(); + // 一级流程 + List firstLevelModels = PALRepositoryCache.getAllSubModelsByPid(wsId, "process"); + if(isEmpty(firstLevelModels)) { + return ro.toString(); + } + //非管理员在测试库下(type:all)权限 + CoeUser coeUserDao = CoeUserDaoFactory.createUser(); + boolean isCoEManager = coeUserDao.isCoEManager(me.getUID()); //是否管理员权限 + + PublisherClientDao publisherDao = new PublisherClientDao(); + List resourceIds = publisherDao.getTeamUserPerms(me.getUID()); //拥有的资源权限 + // + for (PALRepositoryModel model : firstLevelModels) { + if(versionIds.contains(model.getVersionId())) { + continue; + } + // 获取第二级流程 + List secendLevelModels = PALRepositoryCache.getAllSubModelsByPid(wsId, model.getId()); + if(isEmpty(secendLevelModels)) { + continue; + } + for (PALRepositoryModel sModel : secendLevelModels) { + // 获取第三级流程 + List thirdLevelModels = PALRepositoryCache.getAllSubModelsByPid(wsId, sModel.getId()); + if(isEmpty(thirdLevelModels)) { + continue; + } + for(PALRepositoryModel tModel : thirdLevelModels) { + if (type == null || "publish".equals(type) ) {// 获取已发布流程 + if (tModel.isPublish() || "default".equals(tModel.getMethodId())) { + //第四级流程及以下流程 + List possessionList = new ArrayList(); + this.getAllPalRepositoryModelsByPid(wsId, tModel.getId(), possessionList); //递归得到流程信息 + //过滤统计流程的数量 + long possessionCount = 0; + for(int m = 0; m < possessionList.size(); m++) { + PALRepositoryModel mo = possessionList.get(m); + if("process.bpmn2".equals(mo.getMethodId()) && mo.isPublish()) { //只统计process.bpmn2类 + possessionCount ++; + } + } + JSONObject object = new JSONObject(); + object.put("id", tModel.getId()); + object.put("name", tModel.getName()); + object.put("level", tModel.getLevel()); + object.put("parentId", tModel.getParentId()); + object.put("method", tModel.getMethodId()); + object.put("category", tModel.getMethodCategory()); + object.put("parentName", sModel.getName()); + object.put("isPublish", tModel.isPublish()); + object.put("possessionCount", possessionCount); //目录下包含的所有流程数量,只包含bpmn当前版本的 + object.put("privilege", 1); //已发布的正式库永远有权限 + result.add(object); + } + } else {// 获取当前使用中的流程,不区分状态 + if (tModel.isUse()) { + //第四级流程及以下流程 + List possessionList = new ArrayList(); + this.getAllPalRepositoryModelsByPid(wsId, tModel.getId(), possessionList); //递归得到流程信息 + //privalige:0-没有第三级菜单下的流程权限;1-有第三级菜单下的流程权限 + int privalige = 1; + if(!isCoEManager) { + privalige = 0; + for(int i = 0; i < possessionList.size(); i++) { + PALRepositoryModel mo = possessionList.get(i); + if("process.bpmn2".equals(mo.getMethodId()) && mo.isUse() && resourceIds.contains(mo.getId())) { + privalige = 1; + break; + } + } + } + //过滤统计流程的数量 + long possessionCount = 0; + for(int m = 0; m < possessionList.size(); m++) { + PALRepositoryModel mo = possessionList.get(m); + if("process.bpmn2".equals(mo.getMethodId()) && mo.isUse()) { //只统计process.bpmn2类 + possessionCount ++; + } + } + JSONObject object = new JSONObject(); + object.put("id", tModel.getId()); + object.put("name", tModel.getName()); + object.put("level", tModel.getLevel()); + object.put("parentId", tModel.getParentId()); + object.put("method", tModel.getMethodId()); + object.put("category", tModel.getMethodCategory()); + object.put("parentName", sModel.getName()); + object.put("isPublish", tModel.isPublish()); + object.put("possessionCount", possessionCount); //目录下包含的所有流程数量,只包含bpmn当前版本的 + // 非管理人员测试库下 + if(isCoEManager) { + object.put("privilege", 1); //管理员拥有所有权限 + } else { + object.put("privilege", privalige); //非管理员 + } + result.add(object); + } + } + } //end of third level + } + versionIds.add(model.getVersionId()); + } + return ro.toString(); + } + + /** + * 获取某个流程的所有子流程 + * + * @param wsId + * @param pid + * @param list + */ + private void getAllPalRepositoryModelsByPid(String wsId, String pid, List list) { + List children = PALRepositoryCache.getAllSubModelsByPid(wsId, pid); + if (children != null && children.size() > 0) { + list.addAll(children); + for (PALRepositoryModel model : children) { + getAllPalRepositoryModelsByPid(wsId, model.getId(), list); + } + } + } + + /** + * 获取已加入群组 + * @param me + * @return + */ + public String queryJoinedTeamByUserId(UserContext me) { + JSONArray result = new JSONArray(); + // 获取所有工作网络列表 + JSONArray networks = getAllNetworks(); + + // 查询小组列表 + for (Object object : networks) { + JSONObject network = (JSONObject)object; + String networkId = network.getString("id"); + + Map teamMap = new LinkedHashMap(); + //获取工作网络中所有小组 + AppAPI appAPI = SDK.getAppAPI(); + Map params = new HashMap(); + String aslp = "aslp://com.actionsoft.apps.network/queryTeamsByNetwork"; + params.put("networkId", networkId); + params.put("sid", _uc.getSessionId()); + ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(PublisherConf.APPID), aslp, params); + if (ro.toJsonObject().get("data") != null ) { + JSONArray teams = (JSONObject.parseObject(ro.toJsonObject().toString()).getJSONObject("data")).getJSONArray("teams"); + if (teams != null && teams.size() > 0) { + for (int i = 0; i < teams.size(); i++) { + JSONObject team = teams.getJSONObject(i); + if ("1".equals(team.getString("teamStatus"))) + teamMap.put(team.getString("id"), team);// 筛选启用中的小组 + } + } + for (Map.Entry entry : teamMap.entrySet()) { + JSONObject team = entry.getValue(); + String id = team.getString("id"); + // 查询小组成员 + Map numberMap = new HashMap<>(); + //小组ID,必填 + numberMap.put("teamId", id); + numberMap.put("sid", _uc.getSessionId()); + //查询某个小组的成员列表 + ResponseObject teamNumberRo = appAPI.callASLP(appAPI.getAppContext(PublisherConf.APPID), "aslp://com.actionsoft.apps.network/queryTeamMemberByTeamId", numberMap); + if (teamNumberRo.toJsonObject().get("data") != null ) { + JSONArray teamNumbers = (JSONObject.parseObject(teamNumberRo.toJsonObject().toString()).getJSONObject("data")).getJSONArray("teamMembers"); + boolean flag = false; + for (Object o : teamNumbers) { + JSONObject teamNumber = (JSONObject)o; + // 查询是否在当前小组中 + if (teamNumber.getString("userId").equals(_uc.getUID())) { + flag = true; + break; + } + } + if (flag) { + String teamName = team.getString("teamName"); + String teamType = team.getString("teamType"); + String teamTypeIcon = "../apps/com.actionsoft.apps.network/img/team/type_" + teamType + ".png"; + String teamTypeName = ""; + if ("1".equals(teamType)) { + teamTypeName = "公共"; + } else if ("2".equals(teamType)) { + teamTypeName = "私有"; + } else if ("3".equals(teamType)) { + teamTypeName = "私密"; + } + String teamLogo = team.getString("teamLogo"); + String teamLogoSrc = "".equals(teamLogo) ? "../apps/com.actionsoft.apps.network/img/team/logo_2.png" : teamLogo; + int teamMembersNum = team.getInteger("memberAmount") == null ? 0 : team.getInteger("memberAmount"); + // 小组成员 + List numbers = new ArrayList<>(); + for (Object o : teamNumbers) { + JSONObject teamNumber = (JSONObject)o; + numbers.add(teamNumber.getString("userName")); + } + Collections.sort(numbers); + JSONObject teamData = new JSONObject(); + + teamData.put("id", id); + teamData.put("name", teamName); + teamData.put("teamType", teamType); + teamData.put("teamTypeIcon", teamTypeIcon); + teamData.put("teamTypeName", teamTypeName); + teamData.put("teamLogoSrc", teamLogoSrc); + teamData.put("teamMembersNum", teamMembersNum); + teamData.put("numbers", String.join(",", numbers)); + result.add(teamData); + } + } + } + } + } + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(result); + return ro.toString(); + } + + /** + * 获取未加入群组 + * @param me + * @return + */ + public String queryNotJoinTeamByUserId(UserContext me) { + JSONArray result = new JSONArray(); + // 获取所有工作网络列表 + JSONArray networks = getAllNetworks(); + + // 查询小组列表 + for (Object object : networks) { + JSONObject network = (JSONObject)object; + String networkId = network.getString("id"); + + Map teamMap = new LinkedHashMap(); + //获取工作网络中所有小组 + AppAPI appAPI = SDK.getAppAPI(); + Map params = new HashMap(); + String aslp = "aslp://com.actionsoft.apps.network/queryTeamsByNetwork"; + params.put("networkId", networkId); + params.put("sid", _uc.getSessionId()); + ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(PublisherConf.APPID), aslp, params); + if (ro.toJsonObject().get("data") != null ) { + JSONArray teams = (JSONObject.parseObject(ro.toJsonObject().toString()).getJSONObject("data")).getJSONArray("teams"); + if (teams != null && teams.size() > 0) { + for (int i = 0; i < teams.size(); i++) { + JSONObject team = teams.getJSONObject(i); + if ("1".equals(team.getString("teamStatus"))) + teamMap.put(team.getString("id"), team);// 筛选启用中的小组 + } + } + for (Map.Entry entry : teamMap.entrySet()) { + JSONObject team = entry.getValue(); + String id = team.getString("id"); + String teamType = team.getString("teamType"); + if ("3".equals(teamType)) {// 未加入的私密小组不显示 + continue; + } + // 查询小组成员 + Map numberMap = new HashMap<>(); + //小组ID,必填 + numberMap.put("teamId", id); + numberMap.put("sid", _uc.getSessionId()); + //查询某个小组的成员列表 + ResponseObject teamNumberRo = appAPI.callASLP(appAPI.getAppContext(PublisherConf.APPID), "aslp://com.actionsoft.apps.network/queryTeamMemberByTeamId", numberMap); + if (teamNumberRo.toJsonObject().get("data") != null ) { + JSONArray teamNumbers = (JSONObject.parseObject(teamNumberRo.toJsonObject().toString()).getJSONObject("data")).getJSONArray("teamMembers"); + boolean flag = false; + for (Object o : teamNumbers) { + JSONObject teamNumber = (JSONObject)o; + // 查询是否在当前小组中 + if (teamNumber.getString("userId").equals(_uc.getUID())) { + flag = true; + break; + } + } + if (!flag) { + String teamName = team.getString("teamName"); + String teamTypeIcon = "../apps/com.actionsoft.apps.network/img/team/type_" + teamType + ".png"; + String teamTypeName = ""; + if ("1".equals(teamType)) { + teamTypeName = "公共"; + } else if ("2".equals(teamType)) { + teamTypeName = "私有"; + } else if ("3".equals(teamType)) { + teamTypeName = "私密"; + } + String teamLogo = team.getString("teamLogo"); + String teamLogoSrc = "".equals(teamLogo) ? "../apps/com.actionsoft.apps.network/img/team/logo_2.png" : teamLogo; + int teamMembersNum = team.getInteger("memberAmount") == null ? 0 : team.getInteger("memberAmount"); + + JSONObject teamData = new JSONObject(); + + teamData.put("id", id); + teamData.put("name", teamName); + teamData.put("teamType", teamType); + teamData.put("teamTypeIcon", teamTypeIcon); + teamData.put("teamTypeName", teamTypeName); + teamData.put("teamLogoSrc", teamLogoSrc); + teamData.put("teamMembersNum", teamMembersNum); + result.add(teamData); + } + } + } + } + } + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(result); + return ro.toString(); + } + + /** + * 获取工作网络集合 + */ + private JSONArray getAllNetworks() { + JSONArray result = new JSONArray(); + // 调用App + String sourceAppId = PublisherConf.APPID; + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.network/queryAllNetwork"; + // 参数定义列表 + Map params = new HashMap<>(); + params.put("sid", _uc.getSessionId()); + AppAPI appAPI = SDK.getAppAPI(); + //查询工作网络列表 + ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + if (ro.toJsonObject().get("data") != null) { + JSONArray networks = (JSONObject.parseObject(ro.toJsonObject().toString()).getJSONObject("data")).getJSONArray("networks"); + for (Object object : networks) { + JSONObject obj = (JSONObject) object; + JSONObject temp = new JSONObject(); + temp.put("networkName", obj.getString("networkName")); + temp.put("id", obj.getString("id")); + result.add(temp); + } + } + return result; + } + + // 获取所有子部门 + private void getSubDepartments(List list, String parentId) { + // 获取子部门列表 + List subDeptList = SDK.getORGAPI().getSubDepartments(parentId); + if (!isEmpty(subDeptList)) { + for (DepartmentModel model : subDeptList) { + list.add(model); + getSubDepartments(list, model.getId()); + } + } + /*// 获取子部门列表 + List subDeptList = SDK.getORGAPI().getSubDepartments(parentId); + if (!isEmpty(subDeptList)) { + for (DepartmentModel model : subDeptList) { + if (deptIds.contains(model.getId())) { + list.add(model); + } else { + getPermDepartment(list, deptIds, model.getId()); + } + } + }*/ + } + /** + * 查询组织架构中部门流程 + * @param me + * @param wsId + * @return json + */ + public String openProcessMapOrgDeptData(UserContext me, String wsId, String departmentId) { + JSONObject result = new JSONObject(); + //FIXME 由于时间紧急,此方法功能正常,但待优化的地方很多 + // 获取有权限的已发布流程 + String category = "process"; + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + // 过滤当前责任部门的流程 + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + if (model.isPublish() && model.getMethodCategory().equals(category)) { + palProcessIds.add(model.getId()); + } + } + } + } + // 获取关联AWS组织的版本ID且当前为已发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + // 整合所有权限id + palProcessIds.addAll(awsProcessIds); + Set deptIds = new HashSet<>(); + for (String id : palProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null && model.getWsId().equals(wsId)) { + // 责任部门 + String deptId = model.getDutyDept(); + if (!UtilString.isEmpty(deptId)) { + deptIds.add(deptId); + } + } + } + ///// + // 获取子部门列表 + List deptList = new ArrayList<>(); + //getSubDepartments(deptList, departmentId);// 获取子部门列表 + getPermDepartment(deptList, deptIds, departmentId);// 获取子部门列表 + // 部门排序 + JSONArray deptArr = new JSONArray(); + //加入本部门信息 + JSONObject selfDeptObj = new JSONObject(); + SDK.getORGAPI().getDepartmentById(departmentId); + selfDeptObj.put("id", departmentId); + selfDeptObj.put("departmentName", SDK.getORGAPI().getDepartmentById(departmentId).getName()); + deptArr.add(selfDeptObj); + //加入所有下级部门信息 + for (DepartmentModel dept : deptList) { + JSONObject deptObj = new JSONObject(); + deptObj.put("id", dept.getId()); + deptObj.put("departmentName", dept.getName()); + deptArr.add(deptObj); + } + result.put("department", deptArr); + //循环每一个部门得到流程信息 + JSONArray repositoryArr = new JSONArray(); //保存所有的流程 + Set repositoryModel_Ids = new HashSet(); //暂存流程id,保证流程不重复 + if(deptArr!=null && deptArr.size()>0) { + for(Object obj : deptArr) { + JSONObject deptObj = (JSONObject)obj; + //流程的列表 + JSONArray processArray = this.openProcessMapOrgDeptDataBySelfSubDept(me, wsId, deptObj.getString("id"), repositoryModel_Ids); + for(Object processObj : processArray) { + repositoryArr.add(processObj); + } + } + } + result.put("process", repositoryArr); + ResponseObject ro = ResponseObject.newOkResponse(); + ro.setData(result); + return ro.toString(); + } + /** 返回部门下流程 */ + private JSONArray openProcessMapOrgDeptDataBySelfSubDept(UserContext me, String wsId, String departmentId, Set repositoryModel_Ids) { + // 获取有权限的已发布流程 + String category = "process"; + JSONObject param = getXPagesBasicParam(me, null); + String roleId = param.getString("roleId"); + // 过滤当前责任部门的流程 + // 获取PAL权限版本ID + PALRepository repository = new PALRepository(); + Set palVersionIds = repository.getPalVersionIdByroleId(roleId); + Set palProcessIds = new HashSet<>(); + for (String versionId : palVersionIds) { + List list = PALRepositoryCache.getByVersionId(versionId); + if (!isEmpty(list)) { + for (PALRepositoryModel model : list) { + if (model.isPublish() && model.getMethodCategory().equals(category)) { + palProcessIds.add(model.getId()); + } + } + } + } + // 获取关联AWS组织的版本ID且当前为已发布 + Set awsProcessIds = getAwsOrgPermRepositoryByUser(_uc, category, true); + // 整合所有权限id + palProcessIds.addAll(awsProcessIds); + List list = new ArrayList<>(); + for (String id : palProcessIds) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null && model.getWsId().equals(wsId)) { + // 责任部门 + String deptId = model.getDutyDept(); + if (!UtilString.isEmpty(deptId)) { + if (deptId.equals(departmentId)) { + list.add(model); + } + } + } + } + Collections.sort(list, new MyComparator()); + JSONArray repositoryArr = new JSONArray(); + for (PALRepositoryModel model : list) { + if(repositoryModel_Ids.contains(model.getId())) { + //repositoryModel_Ids已经存在该model则略过 + continue; + } + repositoryModel_Ids.add(model.getId());//该modelId加入repositoryModel_Ids,使得下次不重复加入 + + // "子部门列表(部门id,部门名称); + // 所有选择了该部门作为责任部门的流程文件列表(流程id,流程名称,是否有附件、附件Id,附件名称、附件链接、流程地图图片)" + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("version", VersionUtil.getVersionStrV(model.getVersion())); + object.put("hasFile", false); + object.put("method", model.getMethodId()); + object.put("category", model.getMethodCategory()); + // 附件 + JSONArray file = new JSONArray(); + StringBuffer sqlWhere = new StringBuffer(); + sqlWhere.append(" and PALREPOSITORYID ='").append(model.getId()).append("' and FILETYPE='f'"); + UpFileDao upFileDao = new UpFileDao(); + List search = upFileDao.search(sqlWhere.toString()); + if (search != null && search.size() > 0) { + object.put("hasFile", true); + for (UpfileModel upfileModel : search) { + JSONObject fileObject = new JSONObject(); + fileObject.put("id", upfileModel.getUuid()); + fileObject.put("name", upfileModel.getFileName()); + String downloadUrl = ""; + DCContext dcContext = null; + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, CoeFileConstant.COE_UPFILE); + if (dcProfile != null) { + dcContext = new DCContext(me, dcProfile, CoEConstant.APP_ID, "file",upfileModel.getPl_uuid(), upfileModel.getFileName()); + } + if (dcContext != null) { + downloadUrl = dcContext.getDownloadURL() + "&isInline=false"; + } + fileObject.put("url", downloadUrl); + file.add(fileObject); + } + } + object.put("file", file); + // 流程图片 + String imgSrc = ""; + String path = model.getFilePath(); + if (!UtilString.isEmpty(path)) { + UtilFile utilFile = new UtilFile(path + "/" + model.getId() + ".small.png"); + if (utilFile.exists()) { + byte[] base64Bytes = Base64.encode(utilFile.readBytes()); + imgSrc = "data:image/png;base64," + new String(base64Bytes); + } + } + object.put("imgSrc", imgSrc); + repositoryArr.add(object); + } + return repositoryArr; + } + /** + * 依据流程库Id获取该流程库主题风格的轮播图资源 + * @param me + * @return + */ + public String bannerCarouselData(UserContext me ) { + ResponseObject ro = ResponseObject.newOkResponse(); + // dc中文件目录 + DCContext bannerDcContext = null; + DCPluginProfile dcProfile = DCProfileManager.getDCProfile(CoEConstant.APP_ID, "portalTheme"); + if (dcProfile != null) { + bannerDcContext = new DCContext(_uc, dcProfile, "portal", "banner"); + } + // 轮播图文件 + JSONArray pictures = new JSONArray(); + int total = 0; + if (bannerDcContext != null) { + File file = new File(bannerDcContext.getPath()); + if (file.exists()) { + File [] files = file.listFiles(); + if (files != null) { + // 按照名称排序 + List fileList = Arrays.asList(files); + total = fileList.size(); + Collections.sort(fileList, new Comparator() { + @Override + public int compare(File o1, File o2) { + if (o1.isDirectory() && o2.isFile()) + return -1; + if (o1.isFile() && o2.isDirectory()) + return 1; + return o1.getName().compareTo(o2.getName()); + } + }); + for (int i = 0; i < fileList.size(); i++) { + File file2 = files[i]; + String src = new DCContext(_uc, dcProfile, CoEConstant.APP_ID, "portal", "banner", file2.getName()).getDownloadURL(); + JSONObject object = new JSONObject(); + object.put("index", i); + object.put("src", src); + object.put("name", file2.getName()); + pictures.add(object); + } + } + } + } + // + JSONObject data = new JSONObject(); + data.put("pictures", pictures);//图片资源 + data.put("sid", me.getSessionId()); + data.put("total", total); //图片总数 + ro.put("data", data); + return ro.toString(); + } + + /*********************永辉接口end***************************/ + + /** + * 查询“我参与的”流程 + * @param me + * @param count + * @return + */ + public String participantDataQuery(UserContext me, String count) { + int c = Integer.parseInt(count); + if (c < 0) { + throw new AWSException("xpages配置参数错误count=" + count); + } + Map result = new HashMap(); + result.put("sid", me.getSessionId()); + result.put("uid", me.getUID()); + JSONArray array = new JSONArray(); + // 获取当前人权限下的已发布流程ID集合 + Set ids = getAwsOrgPermRealtionRepositoryByUser(me, "process", true); + // 发布时间倒序 + List list = new ArrayList<>(); + for (String id : ids) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null) { + list.add(model); + } + } + Collections.sort(list, new MyComparator());// 排序 + PublishListHistory pHistory = new PublishListHistory(); + for (int i = 0; i < list.size() && i < c; i++) { + PALRepositoryModel model = list.get(i); + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("versionId", model.getVersionId()); + object.put("method", model.getMethodId()); + object.put("date", model.getPublishDate() == null ? "" : model.getPublishDate()); + String taskId = pHistory.getLastPublishTaskIdByModelId(model.getId()); + object.put("taskId", taskId == null ? "" : taskId); + array.add(object); + } + result.put("data", array); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.participant.html", result); + } + + /** + * 查询“我负责的“流程 + * @param me + * @param count + * @return + */ + public String responsibleDataQuery(UserContext me, String count) { + int c = Integer.parseInt(count); + if (c < 0) { + throw new AWSException("xpages配置参数错误count=" + count); + } + Map result = new HashMap(); + result.put("sid", me.getSessionId()); + result.put("uid", me.getUID()); + JSONArray array = new JSONArray(); + // 获取责任人是当前人的已发布流程ID集合 + Set ids = getPermRepositoryByDutyPerson(me, "process", true); + List list = new ArrayList<>(); + for (String id : ids) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null) { + list.add(model); + } + } + Collections.sort(list, new MyComparator());// 排序 + PublishListHistory pHistory = new PublishListHistory(); + for (int i = 0; i < list.size() && i < c; i++) { + PALRepositoryModel model = list.get(i); + JSONObject object = new JSONObject(); + object.put("id", model.getId()); + object.put("name", model.getName()); + object.put("versionId", model.getVersionId()); + object.put("method", model.getMethodId()); + object.put("date", model.getPublishDate() == null ? "" : model.getPublishDate()); + String taskId = pHistory.getLastPublishTaskIdByModelId(model.getId()); + object.put("taskId", taskId == null ? "" : taskId); + array.add(object); + } + result.put("data", array); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.responsible.html", result); + } + + /** + * 岗位职责模块查询 + * @param me + * @param count + * @return + */ + public String postresponsibilityDataQuery(UserContext me, String count) { + int c = Integer.parseInt(count); + if (c < 0) { + throw new AWSException("xpages配置参数错误count=" + count); + } + Map result = new HashMap(); + result.put("sid", me.getSessionId()); + result.put("uid", me.getUID()); + + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.postresponsibility.html", result); + } + + /** + * RCAI模块查询 + * @param me + * @param count + * @return + */ + public String rcaimatrixDataQuery(UserContext me, String count) { + int c = Integer.parseInt(count); + if (c < 0) { + throw new AWSException("xpages配置参数错误count=" + count); + } + Map result = new HashMap(); + result.put("sid", me.getSessionId()); + result.put("uid", me.getUID()); + // 获取当前人的所有角色 + String userId = me.getUID(); + Set roleIds = new HashSet<>(); + RoleModel role = me.getRoleModel(); + roleIds.add(role.getId()); + // 兼职角色 + List userMapModels = UserMapCache.getMapListOfUser(userId); + if (!isEmpty(userMapModels)) { + for (UserMapModel usermap : userMapModels) { + roleIds.add(usermap.getRoleId()); + } + } + // 获取当前人权限下的已发布流程ID集合 + Set ids = getAwsOrgPermRealtionRepositoryByUser(me, "process", true); + List list = new ArrayList<>(); + for (String id : ids) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(id); + if (model != null) { + list.add(model); + } + } + // 按照发布时间/名称排序 + Collections.sort(list, new Comparator() { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + Timestamp time1 = o1.getPublishDate(); + Timestamp time2 = o2.getPublishDate(); + if (time1 != null && time2 != null) { + if (!time1.equals(time2)) { + return time2.compareTo(time1); + } + } + return o1.getName().compareTo(o2.getName()); + } + }); + JSONArray data = new JSONArray(); + int index = 0; + // 获取流程的任务 + for (PALRepositoryModel model : list) { + if (index >= c) { + break; + } + String repositoryId = model.getId(); + String dutyUser = model.getDutyUser(); + String dutyUserName = ""; + if (!UtilString.isEmpty(dutyUser)) { + UserModel userModel = SDK.getORGAPI().getUser(dutyUser); + if (userModel != null) { + dutyUserName = userModel.getUserName(); + } + } + String name = model.getName(); + // 节点集合 + List> shapeList = CoeDesignerUtil.getShapeMessageJson2(repositoryId); + // 排序 + OutputWordUtil.orderByNumber(shapeList); + for (Map shape : shapeList) { + JSONObject trObj = new JSONObject();// 每一行数据 + trObj.put("duty_r", ""); + trObj.put("counselor_c", ""); + trObj.put("approval_a", ""); + trObj.put("notify_i", ""); + Set relation = new HashSet<>(); + JSONObject dataAttributes = (JSONObject)shape.get("attributes"); + if (dataAttributes != null) { + JSONArray dataAttributesJsonArray = dataAttributes.getJSONArray("attributesJsonArray"); + Map shapeModelMap = OutputWordUtil.getShapeRelationMap(repositoryId, (String) shape.get("id")); + boolean flag = false; + for (int i = 0; i < dataAttributesJsonArray.size(); i++) { + String values = ""; + JSONObject dataAttribute = dataAttributesJsonArray.getJSONObject(i); + // 获取awsorg类型等属性 + if (dataAttribute != null && dataAttribute.containsKey("type") && "awsorg".equals(dataAttribute.getString("type"))) { + String key = dataAttribute.getString("key"); + String attributeValue = dataAttribute.getString("value"); + StringBuilder keyValue = new StringBuilder(); + if (key != null) { + if (attributeValue != null && attributeValue.length() != 0) { + attributeValue = attributeValue.replace("[", "").replace("]", "").replace("\"", ""); + String[] keyValues = OutputWordUtil.removeRepeat(attributeValue, ",").split(","); + for (String keyId : keyValues) { + if (!"".equals(keyId) && shapeModelMap.containsKey(keyId)) { + String text = shapeModelMap.get(keyId); + JSONObject object = JSONObject.parseObject(text); + String type = object.getString("type"); + if ("department".equals(type)) {// 部门 + DepartmentModel deptModel = SDK.getORGAPI().getDepartmentById(keyId); + if (deptModel != null) { + keyValue.append(OutputWordUtil.specialCharTransfer(deptModel.getName())).append(","); + } + } + if ("user".equals(type)) {// 人员 + UserModel userModel = SDK.getORGAPI().getUser(keyId); + if (userModel != null) { + if (userModel.getUID().equals(me.getUID())) { + relation.add(dataAttribute.getString("key")); + } + keyValue.append(OutputWordUtil.specialCharTransfer(userModel.getUserName())).append(","); + } + } + if ("role".equals(type)) {// 角色 + RoleModel roleModel = SDK.getORGAPI().getRoleById(keyId); + if (roleModel != null) { + if (roleIds.contains(roleModel.getId())) { + relation.add(dataAttribute.getString("key")); + } + keyValue.append(OutputWordUtil.specialCharTransfer(roleModel.getName())).append(","); + } + } + } + } + } + } + if (keyValue.length() > 0) { + values = keyValue.toString().substring(0, keyValue.length() - 1); + if ("duty_r".equals(dataAttribute.getString("key"))) {// R 责任者 + flag = true; + trObj.put("duty_r", values); + } else if ("counselor_c".equals(dataAttribute.getString("key"))) {// C 咨询者 + flag = true; + trObj.put("counselor_c", values); + } else if ("approval_a".equals(dataAttribute.getString("key"))) {// A 审批者 + flag = true; + trObj.put("approval_a", values); + } else if ("notify_i".equals(dataAttribute.getString("key"))) {// I 知会者 + flag = true; + trObj.put("notify_i", values); + } + } + } + } + if (!flag) { + continue; + } + trObj.put("id", repositoryId);// 流程ID + trObj.put("name", name);// 流程名称 + trObj.put("shapeId", (String) shape.get("id"));// 节点ID + trObj.put("shapeName", shape.get("text").toString());// 任务 + trObj.put("shapeDesc", (OutputWordUtil.specialCharTransfer((String)dataAttributes.get("shapeDesc"))));// 任务描述 + trObj.put("dutyUser", dutyUserName);// 责任人 + trObj.put("relation", ""); + StringBuilder sb = new StringBuilder(); + if (relation.contains("duty_r")) { + sb.append("duty_r").append(","); + } + if (relation.contains("counselor_c")) { + sb.append("counselor_c").append(","); + } + if (relation.contains("approval_a")) { + sb.append("approval_a").append(","); + } + if (relation.contains("notify_i")) { + sb.append("notify_i").append(","); + } + trObj.put("relation", sb.toString()); + data.add(trObj); + index++; + if (index >= c) { + break; + } + } + } + } + result.put("data", data); + return HtmlPageTemplate.merge(PublisherConf.APPID, "publish.client.xpages.rcaimatrix.html", result); + } + + + /** + * 得到流程资产库的数据和组织单元的数据 + * + * @return + */ + public String getCoeWorkSpaceAndOrgInfo() { + ResponseObject ro = ResponseObject.newOkResponse(); + //workspaces:资产库信息;//units:组织单元信息 + JSONObject data = new JSONObject(); + //可用的资产库信息 + List workspaceList = CoeWorkSpaceDaoFactory.createCoeWorkSpace().getCoeWorkSpaceModelRecodesNoPage(); + JSONArray workspaces = new JSONArray(); + if(workspaceList!=null && workspaceList.size()>0) { + for(CoeWorkSpaceModel workspace : workspaceList) { + JSONObject obj = new JSONObject(); + obj.put("id", workspace.getUUId()); + obj.put("name", workspace.getWsName()); + workspaces.add(obj); + } + } + data.put("workspaces", workspaces); + //组织单元信息 + List companyList = SDK.getORGAPI().getCompanys(); + JSONArray companys = new JSONArray(); + if(companyList!=null && companyList.size()>0) { + for(CompanyModel company : companyList) { + JSONObject obj = new JSONObject(); + obj.put("id", company.getId()); + obj.put("name", company.getNameI18N()); + companys.add(obj); + } + } + data.put("companys", companys); + ro.put("data",data); + return ro.toString(); + } + + public String openPage(UserContext me, String uuid, String taskId) { + PALRepositoryModel model = PALRepositoryCache.getCache().get(uuid); + if (model != null && "process".equals(model.getMethodCategory()) && UtilString.isEmpty(taskId)) { + taskId = new PublishListHistory().getLastPublishTaskIdByModelId(uuid); + } + return PALRepositoryQueryAPIManager.getInstance().getPublishPortalHtml(me, uuid, taskId); + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/conf/PublisherConf.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/conf/PublisherConf.java new file mode 100644 index 00000000..d65c5af7 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/conf/PublisherConf.java @@ -0,0 +1,235 @@ +package com.actionsoft.apps.coe.pal.publisher.conf; + +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSONArray; + +public final class PublisherConf { + public static final String APPID = "com.actionsoft.apps.coe.pal.publisher"; + + public static final String RELATION_SEARCH_ID = "com.actionsoft.apps.coe.pal.relationsearch"; + public static final String RELATION_SEARCH_NAME = "关联查询"; + + public static final String PORTAL_TREE_ICON_FOLDER = "../apps/com.actionsoft.apps.coe.pal.publisher/img/tree-folder.png"; + public static final String PORTAL_TREE_ICON_FOLDER1 = "../apps/com.actionsoft.apps.coe.pal.publisher/img/tree-folder1.png"; + + public static String PUBLISH_PORTAL_VERSION = "v1"; + + public static String XPAGES_ID = ""; + + public static JSONArray PORTAL_TABS = null; + + /** + * 页底信息,如客户流程管理部联系信息 + * + * @return + */ + public static String getFotter() { + String value = SDK.getAppAPI().getProperty(APPID, "fotter"); + if (UtilString.isEmpty(value)) { + value = "炎黄盈动"; + } + return value; + } + + public static void setFotter(String fotter) { + fotter = fotter == null ? "" : fotter; + SDK.getAppAPI().setProperty(APPID, "fotter", fotter); + } + + /** + * 门户标题 + * + * @return + */ + public static String getTitle() { + String value = SDK.getAppAPI().getProperty(APPID, "title"); + if (UtilString.isEmpty(value)) { + value = "CoE Process Portal"; + } + return value; + } + + public static void setTitle(String title) { + title = title == null ? "" : title; + SDK.getAppAPI().setProperty(APPID, "title", title); + } + + /** + * 流程发布流程版本Id + * + * @return + */ + public static String getPublishProcessId() { + String value = SDK.getAppAPI().getProperty(APPID, "publishProcessId"); + return value; + } + + /** + * 发布门户的浏览者是否整合AWS用户 + * + * @return 整合返回true + */ + public static boolean isIntegrationAWSUser() { + String value = SDK.getAppAPI().getProperty(APPID, "isIntegrationAWSUser"); + return (value != null && value.trim().equalsIgnoreCase("true")) ? true : false; + } + + /** + * 如果门户未整合AWS用户,此处配置来自外部系统访问门户的统一访客账户。该账户是AWS平台合法的账户 + * + * @return + */ + public static String getGuest() { + String value = SDK.getAppAPI().getProperty(APPID, "guest"); + return value; + } + + /** + * 发布门户的内容允许复制 + * + * @return 允许返回true + */ + public static boolean isCopy() { + String value = SDK.getAppAPI().getProperty(APPID, "isCopy"); + return (value != null && value.trim().equalsIgnoreCase("true")) ? true : false; + } + + public static void setCopy(String isCopy) { + if (isCopy != null && isCopy.trim().equalsIgnoreCase("true")) { + isCopy = "true"; + } else { + isCopy = "false"; + } + SDK.getAppAPI().setProperty(APPID, "isCopy", isCopy); + } + + /** + * 发布门户的内容允许打印 + * + * @return 允许返回true + */ + public static boolean isPrint() { + String value = SDK.getAppAPI().getProperty(APPID, "isPrint"); + return (value != null && value.trim().equalsIgnoreCase("true")) ? true : false; + } + + public static void setPrint(String isPrint) { + if (isPrint != null && isPrint.trim().equalsIgnoreCase("true")) { + isPrint = "true"; + } else { + isPrint = "false"; + } + SDK.getAppAPI().setProperty(APPID, "isPrint", isPrint); + } + + /** + * 发布门户的内容允许留言 + * + * @return 允许返回true + */ + public static boolean isComment() { + String value = SDK.getAppAPI().getProperty(APPID, "isComment"); + return (value != null && value.trim().equalsIgnoreCase("true")) ? true : false; + } + + public static void setComment(String isComment) { + if (isComment != null && isComment.trim().equalsIgnoreCase("true")) { + isComment = "true"; + } else { + isComment = "false"; + } + SDK.getAppAPI().setProperty(APPID, "isComment", isComment); + } + + /** + * 发布门户的内容允许查看属性 + * + * @return 允许返回true + */ + public static boolean isViewAttribute() { + String value = SDK.getAppAPI().getProperty(APPID, "isViewAttribute"); + return (value != null && value.trim().equalsIgnoreCase("true")) ? true : false; + } + + public static void setViewAttribute(String isViewAttribute) { + if (isViewAttribute != null && isViewAttribute.trim().equalsIgnoreCase("true")) { + isViewAttribute = "true"; + } else { + isViewAttribute = "false"; + } + SDK.getAppAPI().setProperty(APPID, "isViewAttribute", isViewAttribute); + } + + /** + * 发布门户的内容允许查看历史发布记录 + * + * @return 允许返回true + */ + public static boolean isViewHistory() { + String value = SDK.getAppAPI().getProperty(APPID, "isViewHistory"); + return (value != null && value.trim().equalsIgnoreCase("true")) ? true : false; + } + + public static void setViewHistory(String isViewHistory) { + if (isViewHistory != null && isViewHistory.trim().equalsIgnoreCase("true")) { + isViewHistory = "true"; + } else { + isViewHistory = "false"; + } + SDK.getAppAPI().setProperty(APPID, "isViewHistory", isViewHistory); + } + + /** + * 流程管理门户xpage + * @param type common:常用流程;frequency:高频流程;systemMap:系统地图;processMap:流程地图;notification:发布动态 + * @return + */ + public static String getXpagesContent(String type) { + StringBuffer content = new StringBuffer(); + switch (type) { + case "common": + content.append(""); + break; + case "frequency": + content.append(""); + break; + case "systemMap": + content.append(""); + break; + case "dataMap": + content.append(""); + break; + case "controlMap": + content.append(""); + break; + case "orgMap": + content.append(""); + break; + case "processMap": + content.append(""); + break; + case "notification": + content.append(""); + break; + case "banner":// 横幅轮播图 + content.append(""); + break; + case "participant":// 我参与的 + content.append(""); + break; + case "responsible":// 我负责的 + content.append(""); + break; + case "postresponsibility":// 岗位职责 + content.append(""); + break; + case "rcaimatrix":// rcai矩阵 + content.append(""); + break; + default: + break; + } + return content.toString(); + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppInstallListener.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppInstallListener.java new file mode 100644 index 00000000..2e3ccce6 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppInstallListener.java @@ -0,0 +1,67 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import com.actionsoft.apps.AppsConst; +import com.actionsoft.apps.listener.AppListener; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.bpms.util.Base64; +import com.actionsoft.exception.AWSException; +import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; + +public class AppInstallListener implements AppListener { + + @SuppressWarnings("resource") + @Override + public void after(AppContext app) { + // 流程管理门户xpages文件同步到xpages应用中 + try { + String path = AppsConst.APPS_ROOT + AppsConst.FOLDER_INSTALL + File.separator + app.getId() + File.separator + "xpages" + File.separator; + File fileDir = new File(path); + if (fileDir.exists()) { + File [] files = fileDir.listFiles(); + for (File file : files) { + InputStream input = null; + ByteArrayOutputStream arrayOutputStream = null; + input = new FileInputStream(file); + arrayOutputStream = new ByteArrayOutputStream(); + byte [] buf = new byte[1024]; + int len = 0; + while ((len = input.read(buf)) != -1) { + arrayOutputStream.write(buf, 0, len); + } + byte [] bytedata = arrayOutputStream.toByteArray(); + String content = new String(Base64.encode(bytedata)); + // 调用App + String sourceAppId = app.getId(); + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.addons.xpages/createTemplateByContent"; + // 参数定义列表 + Map params = new HashMap<>(); + //内容,必填 + params.put("content", content); + //0,覆盖 1不覆盖,非必填 + params.put("overWriteFlag", "0"); + AppAPI appAPI = SDK.getAppAPI(); + //根据一个xpages文件的内容创建一个xpages模板记录 + appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw new AWSException("流程管理门户xpages文件解析错误"); + } + } + + @Override + public boolean before(AppContext arg0) { + return true; + } + +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppStartListener.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppStartListener.java new file mode 100644 index 00000000..8a1298d6 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppStartListener.java @@ -0,0 +1,44 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import com.actionsoft.apps.coe.pal.publisher.conf.PublisherConf; +import com.actionsoft.apps.listener.AppListener; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.exception.AWSException; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; + +public class AppStartListener implements AppListener{ + + @Override + public void after(AppContext arg0) { + // 初始化门户版本 + String value = SDK.getAppAPI().getProperty(PublisherConf.APPID, "portalVersion"); + PublisherConf.PUBLISH_PORTAL_VERSION = value; + if (value.equals("v3")) { + // 初始化门户配置 + String xpagesId = SDK.getAppAPI().getProperty(PublisherConf.APPID, "portalTemplateId_xpages"); + if ("".equals(xpagesId.trim())) { + throw new AWSException("PAL门户默认xpages模版配置参数不允许为空"); + } + PublisherConf.XPAGES_ID = xpagesId; + String portalTabs = SDK.getAppAPI().getProperty(PublisherConf.APPID, "portalTabs"); + if (!"".equals(portalTabs.trim())) { + try { + JSONArray array = JSON.parseArray(portalTabs.trim()); + PublisherConf.PORTAL_TABS = array; + } catch (Exception e) { + throw new AWSException("PAL门户Tab标签配置参数解析出错,请检查参数格式是否正确"); + } + } else { + PublisherConf.PORTAL_TABS = new JSONArray(); + } + } + } + + @Override + public boolean before(AppContext arg0) { + return true; + } + +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppUnInstallListener.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppUnInstallListener.java new file mode 100644 index 00000000..1fa890ed --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/AppUnInstallListener.java @@ -0,0 +1,57 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import com.actionsoft.apps.AppsConst; +import com.actionsoft.apps.lifecycle.log.AppsLogger; +import com.actionsoft.apps.listener.AppListener; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.util.ConsolePrinter; +import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; +import com.alibaba.fastjson.JSONObject; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + + +public class AppUnInstallListener implements AppListener { + + @Override + public void after(AppContext app) { +// TODO Auto-generated method stub + ConsolePrinter.info("publish app custom uninstall"); + System.out.print("publish app custom uninstall"); + ResponseObject ro = ResponseObject.newOkResponse(); + AppAPI appAPI = SDK.getAppAPI(); + String sourceAppId = app.getId(); + String xpagesid = "com.actionsoft.apps.addons.xpages"; + AppContext xpagesApp = appAPI.getAppContext(xpagesid); + AppContext publishApp = appAPI.getAppContext(sourceAppId); + if (xpagesApp != null && SDK.getAppAPI().isActive(xpagesApp.getId())) { + // 服务地址 + String aslp = "aslp://com.actionsoft.apps.addons.xpages/deleteTemplate"; + Map params = new HashMap(); + try { + // 参数定义列表 + String templateId = "30267ab3-aeb6-4371-88e0-ecc13cef94a6"; + params.put("templateId", templateId); + appAPI.callASLP(publishApp, aslp, params); + if (ro.isErr()) { + AppsLogger.err(publishApp, ro.getMsg()); + } + ConsolePrinter.info(ro.toString()); + } catch (Exception e) { + e.printStackTrace(); + ro.err(e.getMessage()); + } + } + + + } + + @Override + public boolean before(AppContext arg0) { + return true; + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishAppCustomAction.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishAppCustomAction.java new file mode 100644 index 00000000..fc355446 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishAppCustomAction.java @@ -0,0 +1,120 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import com.actionsoft.apps.AppsConst; +import com.actionsoft.apps.lifecycle.dist.DistContext; +import com.actionsoft.apps.lifecycle.event.AppCustomActionInterface; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.bpms.util.Base64; +import com.actionsoft.bpms.util.ConsolePrinter; +import com.actionsoft.exception.AWSException; +import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + + +public class PublishAppCustomAction implements AppCustomActionInterface { + + @Override + public void dist(AppContext app, DistContext distCtx) { + // TODO Auto-generated method stub + } + + @Override + public void install(AppContext app) { + ConsolePrinter.info("publish app custom install"); + System.out.print("publish app custom install"); + // 流程管理门户xpages文件同步到xpages应用中 + handleXPagesTemplate(app,"0"); + } + + public void uninstall(AppContext app) { + // TODO Auto-generated method stub + ConsolePrinter.info("publish app custom uninstall"); + System.out.print("publish app custom uninstall"); + //根据publish应用下的模板路径对应删除掉xpages模板 + String path = AppsConst.APPS_ROOT + AppsConst.FOLDER_INSTALL + File.separator + app.getId() + File.separator + "xpages" + File.separator; + ConsolePrinter.info(path); + File fileDir = new File(path); + if (fileDir.exists()) { + File [] files = fileDir.listFiles(); + for (File file : files) { + String sourceAppId = app.getId(); + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.addons.xpages/deleteTemplate"; + // 参数定义列表 + Map params = new HashMap<>(); + String fileName = file.getName(); + String templateId =""; + int dotindex = fileName.lastIndexOf("."); + if (dotindex != -1) { + templateId = fileName.substring(0, dotindex); + } + System.out.print(templateId); + ConsolePrinter.info(templateId); + params.put("templateId", templateId); + AppAPI appAPI = SDK.getAppAPI(); + appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + } + } + + } + + @Override + public void upgrade(AppContext app) { + // TODO Auto-generated method stub + handleXPagesTemplate(app,"0"); + + } + + /** + * 操作xpages模板 + * @param app + * @param overWriteFlag + */ + private void handleXPagesTemplate(AppContext app,String overWriteFlag){ + // 流程管理门户xpages文件同步到xpages应用中 + try { + String path = AppsConst.APPS_ROOT + AppsConst.FOLDER_INSTALL + File.separator + app.getId() + File.separator + "xpages" + File.separator; + ConsolePrinter.info(path); + File fileDir = new File(path); + if (fileDir.exists()) { + File [] files = fileDir.listFiles(); + for (File file : files) { + InputStream input = null; + ByteArrayOutputStream arrayOutputStream = null; + input = new FileInputStream(file); + arrayOutputStream = new ByteArrayOutputStream(); + byte [] buf = new byte[1024]; + int len = 0; + while ((len = input.read(buf)) != -1) { + arrayOutputStream.write(buf, 0, len); + } + byte [] bytedata = arrayOutputStream.toByteArray(); + String content = new String(Base64.encode(bytedata)); + // 调用App + String sourceAppId = app.getId(); + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.addons.xpages/createTemplateByContent"; + // 参数定义列表 + Map params = new HashMap<>(); + //内容,必填 + params.put("content", content); + //0,覆盖 1不覆盖,非必填 + params.put("overWriteFlag", overWriteFlag); + AppAPI appAPI = SDK.getAppAPI(); + //根据一个xpages文件的内容创建一个xpages模板记录 + appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw new AWSException("流程管理门户xpages文件解析错误"); + } + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishInstanceAfterReactivateLIstener.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishInstanceAfterReactivateLIstener.java new file mode 100644 index 00000000..cfd68976 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishInstanceAfterReactivateLIstener.java @@ -0,0 +1,244 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +import com.actionsoft.apps.coe.pal.pal.manage.publish.dao.PublishHistory; +import com.actionsoft.apps.coe.pal.pal.manage.publish.model.PublishHistoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.impl.PALRepositoryModelImpl; +import com.actionsoft.apps.coe.pal.publisher.constant.PublisherConstant; +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext; +import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener; +import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance; +import com.actionsoft.bpms.commons.database.RowMap; +import com.actionsoft.bpms.util.DBSql; +import com.actionsoft.sdk.local.SDK; + +public class PublishInstanceAfterReactivateLIstener extends ExecuteListener{ + + @Override + public String getDescription() { + return "流程复活后进行相关数据还原处理"; + } + + @Override + public String getProvider() { + return "aws-coe"; + } + + @Override + public String getVersion() { + return "V6.3"; + } + + @Override + public void execute(ProcessExecutionContext ctx) throws Exception { + String processInstId = ctx.getProcessInstance().getId(); + ProcessInstance processInstance = ctx.getProcessInstance(); + SDK.getLogAPI().consoleInfo("-----------执行流程复活后事件-------------"); + SDK.getLogAPI().consoleInfo("流程实例标题:" + processInstance.getTitle() + "[processInstId=" + processInstId + "]"); + // 获取相关的流程数据 + + List bolistN = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_N).bindId(processInstId).list(); + List bolistC = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_C).bindId(processInstId).list(); + List bolistS = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_S).bindId(processInstId).list(); + List pList = new ArrayList<>(); + if (bolistN != null) { + for (BO boN : bolistN) { + String publishFileId = boN.get("PUBLISHFILEID").toString(); + PALRepositoryModel palModel = PALRepositoryCache.getCache().get(publishFileId); + if (palModel != null && palModel.isPublish()) {// 若当前为非已发布状态,则不进行处理 + // 若当前流程model.getPalRepositoryId()除此次发布以外存在发布过、变更过、废止过,则退回至停用状态,否则退回至设计状态 + // List allPublishData = listDao.query("PALREPOSITORYID = ?", publishFileId).list(); + List allPublishData = DBSql.getMaps("SELECT ID FROM SYS_COE_PAL_PUBLISH_LIST WHERE PALREPOSITORYID = ?", new Object[] {publishFileId}); + if (allPublishData != null) { + boolean isPublish = false; + boolean isStop = false; + boolean isApproval = false; + if (allPublishData.size() > 1) { + // 退回至停用状态 + isStop = true; + } else { + // 退回至设计状态 + } + createResultMap(palModel.getName(), palModel.getId(), isPublish, isStop, isApproval, pList); + } + } + + } + } + if (bolistC != null) { + for (BO boC : bolistC) { + String changefileId = boC.get("CHANGEFILEID").toString();// 变更文件id + String changedFileIdNew = boC.get("CHANGEDFILEIDNEW").toString();// 变更后文件id + PALRepositoryModel changeModel = PALRepositoryCache.getCache().get(changefileId); + PALRepositoryModel changeNewModel = PALRepositoryCache.getCache().get(changedFileIdNew); + // 符合该条件可进行复活,状态值不符合则暂时不处理 + if (changeModel != null && changeNewModel != null && changeModel.isStop() && changeNewModel.isPublish()) { + // changeModel退回至已发布状态 + boolean isPublish = true; + boolean isStop = false; + boolean isApproval = false; + createResultMap(changeModel.getName(), changefileId, isPublish, isStop, isApproval, pList); + // List allchangeData = listDao.query("PALREPOSITORYID = ?", changedFileIdNew).list(); + List allchangeData = DBSql.getMaps("SELECT ID FROM SYS_COE_PAL_PUBLISH_LIST WHERE PALREPOSITORYID = ?", new Object[] {changedFileIdNew}); + if (allchangeData != null) { + isPublish = false; + isStop = false; + isApproval = false; + if (allchangeData.size() > 1) { + // changeNewModel退回至停用状态 + isStop = true; + } else { + // changeNewModel退回至设计状态 + } + createResultMap(changeNewModel.getName(), changedFileIdNew, isPublish, isStop, isApproval, pList); + + } + } + } + } + + if (bolistS != null) { + for (BO boS : bolistS) { + String stopFileId = boS.get("STOPFILEID").toString(); + PALRepositoryModel stopModel = PALRepositoryCache.getCache().get(stopFileId); + // 已停用且该流程版本下所有流程没有在发布状态的进行退回,保证退回之后该流程所有版本中只有一条为已发布状态 + if (stopModel != null && stopModel.isStop()) { + List stopList = PALRepositoryCache.getByVersionId(stopModel.getVersionId()); + boolean flag = false; + for (PALRepositoryModel model : stopList) { + if (model.isPublish()) { + flag = true; + break; + } + } + if (!flag) { + // 退回至已发布状态 + boolean isPublish = true; + boolean isStop = false; + boolean isApproval = false; + createResultMap(stopModel.getName(), stopFileId, isPublish, isStop, isApproval, pList); + } + } + } + } + if (pList.size() > 0) { + restoreData(pList, processInstId); + + } + } + + /** + * 还原数据 + * @param pList + * @param processInstId + */ + private void restoreData(List pList, String processInstId) { + // 批量处理回退数据 + boolean flag = batchHandleRepositoryData(pList); + int r = 0; + if (flag) { + // 删除SYS_COE_PAL_PUBLISH和SYS_COE_PAL_PUBLISH_LIST表数据 + PublishHistory dao = new PublishHistory();// 发布结果主表 + PublishHistoryModel history = dao.queryBy("PROCESSINSTID = ?", processInstId); + if (history != null) { + r = dao.delete(history.getId()); + } + SDK.getLogAPI().consoleInfo("流程状态还原,变更数据[" + pList.size() + "]条"); + for (PALRepositoryModel model : pList) { + SDK.getLogAPI().consoleInfo("流程名称:" + model.getName() + "[id=" + model.getId() + ",isPublish=" + model.isPublish() + ",isStop=" + model.isStop() + "]"); + } + if (r > 0) { + SDK.getLogAPI().consoleInfo("删除发布结果数据成功[processInstId=" + processInstId + "]"); + } + } + } + + /** + * 流程数据库状态还原 + * @param pList + * @return + */ + private boolean batchHandleRepositoryData(List pList) { + boolean completeSuccess = false; + Connection conn = DBSql.open(); + PreparedStatement ps = null; + java.sql.ResultSet rset = null; + Timestamp nowTime = new Timestamp(System.currentTimeMillis()); + try { + conn.setAutoCommit(false); + String sql = "UPDATE " + PALRepositoryModelImpl.DATABASE_ENTITY + " SET " + + PALRepositoryModelImpl.FIELD_PL_ISPUBLISH + " =?, " + + PALRepositoryModelImpl.FIELD_PL_ISSTOP + "= ?," + + PALRepositoryModelImpl.FIELD_PL_MODIFYDATE + " = ? WHERE " + + PALRepositoryModelImpl.FIELD_UUID + "=?"; + ps = conn.prepareStatement(sql); + for (int i = 0; i < pList.size(); i++) { + String id = pList.get(i).getId(); + int isPublish = pList.get(i).isPublish() ? 1 : 0; + int isStop = pList.get(i).isStop() ? 1 : 0; + ps.setInt(1, isPublish); + ps.setInt(2, isStop); + ps.setTimestamp(3, nowTime); + ps.setString(4, id); + ps.addBatch(); + } + int[] results = ps.executeBatch(); + for (int i = 0; i < results.length; i++) { + if ((results[i] >= 0) || (results[i] == PreparedStatement.SUCCESS_NO_INFO)) { + completeSuccess = true; + } + } + if (completeSuccess) { + conn.commit(); + PALRepository dao = new PALRepository(); + for (PALRepositoryModel model : pList) { + PALRepositoryModel model2 = dao.getInstance(model.getId()); + if (model2 != null) { + PALRepositoryCache.getCache().put(model2.getId(), model2); + } + } + } else { + conn.rollback(); + PALRepositoryCache.getCache().reload(); + } + } catch (SQLException e) { + try { + conn.rollback(); + } catch (SQLException e1) { + e1.printStackTrace(); + } + e.printStackTrace(); + } finally { + DBSql.close(conn, ps, rset); + } + return completeSuccess; + } + + /** + * 结果集,用于批量处理数据源 + * @param id + * @param isPublish + * @param isStop + * @param isApproval + */ + private void createResultMap(String name, String id, boolean isPublish, boolean isStop, boolean isApproval, List pList) { + PALRepositoryModelImpl modelImpl = new PALRepositoryModelImpl(); + modelImpl.setId(id); + modelImpl.setName(name); + modelImpl.setPublish(isPublish); + modelImpl.setStop(isStop); + // modelImpl.setApproval(isApproval);// 不处理 + pList.add(modelImpl); + } + +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishProcessAfterDeleteListener.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishProcessAfterDeleteListener.java new file mode 100644 index 00000000..d1bc7bfb --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/PublishProcessAfterDeleteListener.java @@ -0,0 +1,50 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository; +import com.actionsoft.apps.coe.pal.publisher.constant.PublisherConstant; +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext; +import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener; +import com.actionsoft.sdk.local.SDK; + +import java.util.List; + +public class PublishProcessAfterDeleteListener extends ExecuteListener { + + @Override + public String getDescription() { + return "流程实例删除后更改模型文件的状态信息"; + } + + @Override + public String getProvider() { + return "aws-coe"; + } + + @Override + public void execute(ProcessExecutionContext param) throws Exception { + String processInstId = param.getProcessInstance().getId(); + // 发布的 + List bolistN = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_N).bindId(processInstId).list(); + PALRepository repositoryDao = new PALRepository(); + if (bolistN != null) { + for (BO boN : bolistN) { + repositoryDao.updateIsApproval(0,boN.get("PUBLISHFILEID").toString()); + } + } + // 变更的 + List bolistC = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_C).bindId(processInstId).list(); + if (bolistC != null) { + for (BO boC : bolistC) { + repositoryDao.updateIsApproval(0,boC.get("CHANGEDFILEIDNEW").toString()); + } + } + // 停用的 + List bolistS = SDK.getBOAPI().query(PublisherConstant.BOSUBTABLE_S).bindId(processInstId).list(); + if (bolistS != null) { + for (BO boS : bolistS) { + repositoryDao.updateIsApproval(0,boS.get("STOPFILEID").toString()); + } + } + } +} diff --git a/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/SubFormGridFilterListener.java b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/SubFormGridFilterListener.java new file mode 100644 index 00000000..c7d2a3a8 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.publisher/src/com/actionsoft/apps/coe/pal/publisher/event/SubFormGridFilterListener.java @@ -0,0 +1,71 @@ +package com.actionsoft.apps.coe.pal.publisher.event; + +import java.util.List; + +import com.actionsoft.bpms.bo.design.model.BOItemModel; +import com.actionsoft.bpms.bo.engine.BO; +import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext; +import com.actionsoft.bpms.bpmn.engine.listener.FormGridFilterListener; +import com.actionsoft.bpms.bpmn.engine.listener.FormGridRowLookAndFeel; +import com.actionsoft.bpms.bpmn.engine.listener.ListenerConst; +import com.actionsoft.bpms.form.design.model.FormItemModel; + +public class SubFormGridFilterListener extends FormGridFilterListener { + + @Override + public FormGridRowLookAndFeel acceptRowData(ProcessExecutionContext context, List boItemList, BO boData) { + String tableName = context.getParameterOfString(ListenerConst.FORM_EVENT_PARAM_BONAME); + if (tableName.equals("BO_ACT_COE_PUBLISH_N")) { + //创建一个对象 + FormGridRowLookAndFeel diyLookAndFeel = new FormGridRowLookAndFeel(); + String fileName = boData.getString("PUBLISHFILENAME"); + if (fileName != null) { + boData.set("PUBLISHFILENAME", "" + fileName + "");// 重新设定一个字段的值 + } + + boData.set("字段子表字段名", "|"); + + //处理好之后,将该对象返回 + return diyLookAndFeel; + } else if (tableName.equals("BO_ACT_COE_PUBLISH_C")) { + //创建一个对象 + FormGridRowLookAndFeel diyLookAndFeel = new FormGridRowLookAndFeel(); + String fileName1 = boData.getString("CHANGEFILENAME"); + if (fileName1 != null) { + boData.set("CHANGEFILENAME", "" + fileName1 + "");// 重新设定一个字段的值 + } + String fileName2 = boData.getString("CHANGEDFILENAMENEW"); + if (fileName2 != null) { + boData.set("CHANGEDFILENAMENEW", "" + fileName2 + "");// 重新设定一个字段的值 + } + + boData.set("字段子表字段名", "|"); + + //处理好之后,将该对象返回 + return diyLookAndFeel; + } else if (tableName.equals("BO_ACT_COE_PUBLISH_S")) { + //创建一个对象 + FormGridRowLookAndFeel diyLookAndFeel = new FormGridRowLookAndFeel(); + String fileName = boData.getString("STOPFILENAME"); + if (fileName != null) { + boData.set("STOPFILENAME", "" + fileName + "");// 重新设定一个字段的值 + } + boData.set("字段子表字段名", "|"); + + //处理好之后,将该对象返回 + return diyLookAndFeel; + } + return null; + } + + @Override + public String getCustomeTableHeaderHtml(ProcessExecutionContext arg0, FormItemModel arg1, List arg2) { + return null; + } + + @Override + public String orderByStatement(ProcessExecutionContext arg0) { + return null; + } + +}