diff --git a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java index a25e49b2..cdef7742 100644 --- a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java +++ b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java @@ -65,10 +65,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; import java.util.stream.Collectors; /** @@ -82,7 +79,7 @@ public class ActTaskService extends BaseServiceImpl { private static final ObjectMapper oMapper = new ObjectMapper(); private static final Integer CPUNUM = Runtime.getRuntime().availableProcessors(); - private static final ExecutorService executor = Executors.newFixedThreadPool(CPUNUM); + private static final ExecutorService executor = Executors.newWorkStealingPool(CPUNUM * 2); public static String Task_HANDLE_STATE = "handleState"; //任务节点处理状态key public static String Task_HANDLE_STATE_AGREE = "agree"; //同意 @@ -193,11 +190,21 @@ public class ActTaskService extends BaseServiceImpl { } List tasks = nativeTaskQuery.listPage((curPage - 1) * limit, limit); long count = nativeCountTaskQuery.count(); + List completableFutures = new ArrayList(); + final TaskQuery taskQuery = taskService.createTaskQuery(); List list_ = tasks.stream().map(index -> { - TaskQuery taskQuery = taskService.createTaskQuery(); - Task temp = taskQuery.taskId(index.getId()).includeProcessVariables().singleResult(); + CompletableFuture tempTask = CompletableFuture.supplyAsync(() -> taskQuery.taskId(index.getId()).includeProcessVariables().singleResult(), executor); + Task temp = null; + try { + temp = (Task) tempTask.get(); + } catch (InterruptedException e) { + logger.error("异步获取失败", e); + } catch (ExecutionException e) { + logger.error("异步获取失败", e); + } return temp; - }).collect(Collectors.toList()); + }).filter(Objects::nonNull).collect(Collectors.toList()); + CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[completableFutures.size()])).join(); return new PageData<>(tasks2TaskDtos(list_), (int) count); // 以下注释为原实现方案 // TaskQuery taskQuery = taskService.createTaskQuery(); diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index daab8522..26673d1c 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -755,8 +755,8 @@ public class ResourceServiceImpl extends CrudServiceImpl { HashMap map = (HashMap) this.selectInfrastructureList(); final Long[] total = {0L}; - map.forEach((k,v) -> { - total[0] = total[0] + (Integer) v; + map.forEach((k, v) -> { + total[0] = total[0] + (Integer) v; }); re.add(new HashMap() { { @@ -1438,9 +1438,9 @@ public class ResourceServiceImpl extends CrudServiceImpl> result2; if (Long.parseLong(params.get("id").toString()) == 0) { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName,\n" + "SUM(a.visits) AS resourceVisits \n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '组件服务' AND a.del_flag = 0\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n"); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName, " + "SUM(a.visits) AS resourceVisits " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '组件服务' AND a.del_flag = 0 " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name "); } else { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName,\n" + "SUM(a.visits) AS resourceVisits \n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '组件服务' AND a.del_flag = 0\n" + "AND (b.ID = ? OR INSTR(b.pids,?))\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n", pas); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName, " + "SUM(a.visits) AS resourceVisits " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '组件服务' AND a.del_flag = 0 " + "AND (b.ID = ? OR INSTR(b.pids,?)) " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name ", pas); } if (!result2.isEmpty()) { @@ -1518,9 +1518,9 @@ public class ResourceServiceImpl extends CrudServiceImpl> result2; if (Long.parseLong(params.get("id").toString()) == 0) { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName\n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '应用资源' AND a.del_flag = 0\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n"); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '应用资源' AND a.del_flag = 0 " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name "); } else { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName\n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '应用资源' AND a.del_flag = 0\n" + "AND (b.ID = ? OR b.pids LIKE CONCAT(CONCAT('%',?),'%'))\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n", pas); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '应用资源' AND a.del_flag = 0 " + "AND (b.ID = ? OR b.pids LIKE CONCAT(CONCAT('%',?),'%')) " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name ", pas); } if (!result2.isEmpty()) { @@ -1615,9 +1615,9 @@ public class ResourceServiceImpl extends CrudServiceImpl> result2; if (Long.parseLong(params.get("id").toString()) == 0) { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName\n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '基础设施' AND a.del_flag = 0\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n"); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '基础设施' AND a.del_flag = 0 " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name "); } else { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName\n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '基础设施' AND a.del_flag = 0\n" + "AND (b.ID = ? OR INSTR(b.pids,?))\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n", pas); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '基础设施' AND a.del_flag = 0 " + "AND (b.ID = ? OR INSTR(b.pids,?)) " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name ", pas); } if (!result2.isEmpty()) { @@ -1663,9 +1663,9 @@ public class ResourceServiceImpl extends CrudServiceImpl> result2; if (Long.parseLong(params.get("id").toString()) == 0) { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName\n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '数据资源' AND a.del_flag = 0\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n"); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '数据资源' AND a.del_flag = 0 " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name "); } else { - result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName\n" + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id\n" + "WHERE a.type = '数据资源' AND a.del_flag = 0\n" + "AND (b.ID = ? OR INSTR(b.pids,?))\n" + "GROUP BY a.dept_id,b.name\n" + "ORDER BY a.dept_id,b.name\n", pas); + result2 = jdbcTemplate.queryForList("SELECT COUNT(a.id) AS resourceNum,a.dept_id AS deptId,b.name AS deptName " + "FROM tb_data_resource a INNER JOIN sys_dept b ON a.dept_id = b.id " + "WHERE a.type = '数据资源' AND a.del_flag = 0 " + "AND (b.ID = ? OR INSTR(b.pids,?)) " + "GROUP BY a.dept_id,b.name " + "ORDER BY a.dept_id,b.name ", pas); } @@ -1711,9 +1711,9 @@ public class ResourceServiceImpl extends CrudServiceImpl>> partition = Lists.partition(result, pageSize); @@ -2235,27 +2235,31 @@ public class ResourceServiceImpl extends CrudServiceImpl(); } else { - StringBuilder sb = new StringBuilder("SELECT\n" + - "\tCOUNT( BSNUM ) AS \"count\",\n" + - "\t'yzy' AS \"type\" \n" + - "FROM\n" + - "\tVIEW_CLOUD_BUSINESS_INDEX \n" + - "WHERE\n" + - "\t1 = 1 \n" + - "\tAND ORG_NAME = '"); + StringBuilder sb = new StringBuilder("SELECT " + + " COUNT( BSNUM ) AS \"count\", " + + " 'yzy' AS \"type\" " + + "FROM " + + " VIEW_CLOUD_BUSINESS_INDEX " + + "WHERE " + + " 1 = 1 " + + " AND ORG_NAME = '"); sb.append(lcDept.get("lc_name").toString()) - .append("' UNION ALL\n" + - "SELECT\n" + - "\tCOUNT( BSNUM ) AS \"count\",\n" + - "\t'ysp' AS \"type\" \n" + - "FROM\n" + - "\tVIEW_VIDEO_BUSINESS_INDEX \n" + - "WHERE\n" + - "\t1 = 1 \n" + - "\tAND ORG_NAME = '") + .append("' UNION ALL " + + "SELECT " + + " COUNT( BSNUM ) AS \"count\", " + + " 'ysp' AS \"type\" " + + "FROM " + + " VIEW_VIDEO_BUSINESS_INDEX " + + "WHERE " + + " 1 = 1 " + + " AND ORG_NAME = '") .append(lcDept.get("lc_name").toString()) .append("'"); - zwyCountListByapplyDept.addAll(lcJdbcTemplate.queryForList(sb.toString())); + try { + zwyCountListByapplyDept.addAll(lcJdbcTemplate.queryForList(sb.toString())); + } catch (Exception e) { + logger.error(sb.toString(), e); + } } List> typeCountListByApplyDept = resourceDao.selectApplyDeptDetailTypeCountList(params); @@ -2294,7 +2298,12 @@ public class ResourceServiceImpl extends CrudServiceImpl> typeCountListByApplyDept = resourceDao.selectApplyDeptDetailTypeCountList(params); if ("250000".equals(params.get("region").toString())) { - List> zwyCountListByApplyDept = lcJdbcTemplate.queryForList(getAllsql); + List> zwyCountListByApplyDept = new ArrayList<>(); + try { + zwyCountListByApplyDept = lcJdbcTemplate.queryForList(getAllsql); + } catch (Exception e) { + logger.error(getAllsql, e); + } zwyCountListByApplyDept.forEach(x -> { Map ucsDept = sysDeptDao.selectUCSDeptByLCDeptName(x.get("deptName").toString()); @@ -2337,8 +2346,12 @@ public class ResourceServiceImpl extends CrudServiceImpl> zwyCountListByApplyDept = lcJdbcTemplate.queryForList(getAllsql); + List> zwyCountListByApplyDept = new ArrayList<>(); + try { + zwyCountListByApplyDept = lcJdbcTemplate.queryForList(getAllsql); + } catch (Exception e) { + logger.info(getAllsql, e); + } zwyCountListByApplyDept.forEach(x -> { Map ucsDept = sysDeptDao.selectUCSDeptByLCDeptName(x.get("deptName").toString()); @@ -2735,12 +2748,12 @@ public class ResourceServiceImpl extends CrudServiceImpl { - Map map = (Map) x; + Map map = (Map) x; return DateUtils.parse(map.get("createDate").toString(), DateUtils.DATE_TIME_PATTERN); - }).reversed()) + }).reversed()) .skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList()); return new PageData(result, total.intValue()); - } else if ("云资源".equals(params.get("resourceType").toString()) || "云视频".equals(params.get("resourceType").toString())){ + } else if ("云资源".equals(params.get("resourceType").toString()) || "云视频".equals(params.get("resourceType").toString())) { List lcApplyDtoList = lcSelectCensusApplyTable(params); result.addAll(lcApplyDtoList.stream().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList())); return new PageData(result, lcApplyDtoList.size()); @@ -2754,50 +2767,58 @@ public class ResourceServiceImpl extends CrudServiceImpl lcSelectCensusApplyTable(Map params) { - StringBuilder sb = new StringBuilder("SELECT * FROM (\n" + - "SELECT\n" + - "\tvcbi.ORG_NAME AS \"deptName\", bsrel.name AS \"resourceName\", '青岛市大数据发展管理局' AS \"resourceDeptName\",\n" + - "\tbsrel.SOURCE_TYPE AS \"type\", to_char( vcbi.CREATE_TIME, 'yyyy-mm-dd HH24:MI:SS' ) AS \"createDate\",\n" + - "\tvcbi.status AS \"approveStatus\", bsrel.BSNUM AS \"applyNumber\" \n" + - "FROM\n" + - "\t(\n" + - "\t\tSELECT BSNUM, '云主机' AS \"SOURCE_TYPE\", NAME, DISPOSE AS \"INFO\" FROM VIEW_CLOUD_HOST_INFO \n" + - "\t\tUNION ALL\n" + - "\t\tSELECT BSNUM, '云数据库' AS \"SOURCE_TYPE\", NAME, (TYPE || '/' || STORAGE_SPACE || 'GB') AS \"INFO\" FROM VIEW_CLOUD_DATABASE_INFO \n" + - "\t\tUNION ALL\n" + - "\t\tSELECT BSNUM, '对象存储' AS \"SOURCE_TYPE\", NAME, ( DATA_DISK || 'GB' ) AS \"INFO\" FROM VIEW_CLOUD_OBJECTSTORAGE_INFO \n" + - "\t\tUNION ALL\n" + - "\t\tSELECT BSNUM, '托管服务' AS \"SOURCE_TYPE\", NAME, U_NUM AS \"INFO\" FROM VIEW_TRUSTEESHIPSERVICE_INFO\n" + - "\t) bsrel\n" + - "\tLEFT JOIN VIEW_CLOUD_BUSINESS_INDEX vcbi ON bsrel.BSNUM = vcbi.BSNUM \n" + - "WHERE\n" + - "\tvcbi.APPLYTYPE = '01' \n" + - "\tAND vcbi.status IN ( '01', '03', '04', '05', '06', '99' )\n" + - "\tUNION ALL\n" + - "\tSELECT vvbi.ORG_NAME AS \"deptName\", vvbr.name AS \"resourceName\", vvbr.ORG_NAME AS \"resourceDeptName\",\n" + - "\t'云视频' AS \"type\", to_char( vvbi.CREATE_TIME, 'yyyy-mm-dd HH24:MI:SS' ) AS \"createDate\", vvbi.status AS \"approveStatus\", \n" + - "\tvvbr.BSNUM AS \"applyNumber\" \n" + - "FROM\n" + - "\tVIEW_VIDEO_BUSINESS_RELATION vvbr\n" + - "\tLEFT JOIN VIEW_VIDEO_BUSINESS_INDEX vvbi ON vvbr.BSNUM = vvbi.BSNUM \n" + - "WHERE\n" + - "\tvvbi.STATUS != '00'\n" + - "\tAND vvbr.ORG_NAME IS NOT NULL \n" + - "\t) apply \n" + - "\tWHERE 1 = 1\n" + - "\t\n"); + StringBuilder sb = new StringBuilder("SELECT * FROM ( " + + "SELECT " + + " vcbi.ORG_NAME AS \"deptName\", bsrel.name AS \"resourceName\", '青岛市大数据发展管理局' AS \"resourceDeptName\", " + + " bsrel.SOURCE_TYPE AS \"type\", to_char( vcbi.CREATE_TIME, 'yyyy-mm-dd HH24:MI:SS' ) AS \"createDate\", " + + " vcbi.status AS \"approveStatus\", bsrel.BSNUM AS \"applyNumber\" " + + "FROM " + + " ( " + + " SELECT BSNUM, '云主机' AS \"SOURCE_TYPE\", NAME, DISPOSE AS \"INFO\" FROM VIEW_CLOUD_HOST_INFO " + + " UNION ALL " + + " SELECT BSNUM, '云数据库' AS \"SOURCE_TYPE\", NAME, (TYPE || '/' || STORAGE_SPACE || 'GB') AS \"INFO\" FROM VIEW_CLOUD_DATABASE_INFO " + + " UNION ALL " + + " SELECT BSNUM, '对象存储' AS \"SOURCE_TYPE\", NAME, ( DATA_DISK || 'GB' ) AS \"INFO\" FROM VIEW_CLOUD_OBJECTSTORAGE_INFO " + + " UNION ALL " + + " SELECT BSNUM, '托管服务' AS \"SOURCE_TYPE\", NAME, U_NUM AS \"INFO\" FROM VIEW_TRUSTEESHIPSERVICE_INFO " + + " ) bsrel " + + " LEFT JOIN VIEW_CLOUD_BUSINESS_INDEX vcbi ON bsrel.BSNUM = vcbi.BSNUM " + + "WHERE " + + " vcbi.APPLYTYPE = '01' " + + " AND vcbi.status IN ( '01', '03', '04', '05', '06', '99' ) " + + " UNION ALL " + + " SELECT vvbi.ORG_NAME AS \"deptName\", vvbr.name AS \"resourceName\", vvbr.ORG_NAME AS \"resourceDeptName\", " + + " '云视频' AS \"type\", to_char( vvbi.CREATE_TIME, 'yyyy-mm-dd HH24:MI:SS' ) AS \"createDate\", vvbi.status AS \"approveStatus\", " + + " vvbr.BSNUM AS \"applyNumber\" " + + "FROM " + + " VIEW_VIDEO_BUSINESS_RELATION vvbr " + + " LEFT JOIN VIEW_VIDEO_BUSINESS_INDEX vvbi ON vvbr.BSNUM = vvbi.BSNUM " + + "WHERE " + + " vvbi.STATUS != '00' " + + " AND vvbr.ORG_NAME IS NOT NULL " + + " ) apply " + + " WHERE 1 = 1 " + + " "); if (params.get("provideDept") != null) { Map lcDept = sysDeptDao.selectLCDeptByUcsDeptName(params.get("provideDept").toString()); - if (lcDept.isEmpty() || org.apache.commons.lang3.StringUtils.isBlank(lcDept.get("lc_name").toString())) { - logger.error("未查询到{}对应的浪潮系统部门", params.get("provideDept").toString()); + try { + if (lcDept.isEmpty() + || lcDept.get("lc_name") == null + || (lcDept.get("lc_name") != null && org.apache.commons.lang3.StringUtils.isBlank(lcDept.get("lc_name").toString())) + ) { + logger.error("未查询到{}对应的浪潮系统部门", params.get("provideDept").toString()); + return new ArrayList<>(); + } + sb.append(" AND apply.\"resourceDeptName\" = ").append(lcDept.get("lc_name").toString()); + } catch (Exception e) { + logger.error("", e); return new ArrayList<>(); } - sb.append(" AND apply.\"resourceDeptName\" = ").append(lcDept.get("lc_name").toString()); } if (params.get("region") != null) { - List deptNames = sysDeptDao.selectLCDeptByRegion((Long)params.get("region")); + List deptNames = sysDeptDao.selectLCDeptByRegion((Long) params.get("region")); logger.error("只查询本区域部门申请,部门列表{}", deptNames); sb.append(" AND apply.\"deptName\" IN ( "); deptNames.forEach(name -> sb.append("'").append(name).append("', "));