From df7e2a382425e4b0564bbe0f489b859ba10badd0 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Tue, 19 Jul 2022 15:06:38 +0800 Subject: [PATCH] =?UTF-8?q?deptToDoTaskPage=E6=8E=A5=E5=8F=A3=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activiti/service/ActTaskService.java | 40 ++-- .../sys/service/impl/SysUserServiceImpl.java | 177 +++++++++--------- .../main/resources/mapper/sys/SysUserDao.xml | 3 + 3 files changed, 122 insertions(+), 98 deletions(-) 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 909cc6fc..4a804305 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 @@ -21,7 +21,6 @@ import io.renren.modules.resourceMountApply.dto.TResourceMountApplyDTO; import io.renren.modules.resourceMountApply.service.TResourceMountApplyService; import io.renren.modules.security.user.SecurityUser; import io.renren.modules.sys.dto.SysUserDTO; -import io.renren.modules.sys.entity.SysUserEntity; import io.renren.modules.sys.service.SysRoleUserService; import io.renren.modules.sys.service.SysUserService; import org.activiti.engine.HistoryService; @@ -55,6 +54,10 @@ 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.stream.Collectors; /** @@ -67,6 +70,9 @@ public class ActTaskService extends BaseServiceImpl { private static final Logger logger = LoggerFactory.getLogger(ActTaskService.class); private static final ObjectMapper oMapper = new ObjectMapper(); + private static Integer cpuNUm = Runtime.getRuntime().availableProcessors(); + private static final ExecutorService executor = Executors.newFixedThreadPool(cpuNUm); + public static String Task_HANDLE_STATE = "handleState"; //任务节点处理状态key public static String Task_HANDLE_STATE_AGREE = "agree"; //同意 public static String Task_HANDLE_STATE_REJECTED = "rejected"; //驳回 @@ -160,17 +166,25 @@ public class ActTaskService extends BaseServiceImpl { limit = Integer.parseInt((String) params.get(Constant.LIMIT)); } List sysUserList = sysUserService.list(new HashMap()); - List taskDtoList = new ArrayList<>(); - for (SysUserDTO user : sysUserList) { - String userId = user.getId().toString(); - TaskQuery taskQuery = taskService.createTaskQuery(); - if (StringUtils.isNotEmpty(userId)) { - taskQuery.taskAssignee(userId); - } - taskQuery.orderByTaskCreateTime().desc(); - List list = taskQuery.active().includeProcessVariables().list(); - taskDtoList.addAll(tasks2TaskDtos(list)); - } + List taskDtoList = new CopyOnWriteArrayList<>(); + Integer finalCurPage = curPage; + Integer finalLimit = limit; + List count = new CopyOnWriteArrayList<>(); + List completableFutureList = + sysUserList.stream().filter(index -> null != index.getId()).map(index -> { + CompletableFuture completableFuture = CompletableFuture.runAsync(() -> { + TaskQuery taskQuery = taskService.createTaskQuery(); + List list = taskQuery.taskAssignee(index.getId().toString()) + .orderByTaskCreateTime().desc() + .includeProcessVariables() + .listPage((finalCurPage - 1) * finalLimit, finalCurPage * finalLimit); + count.add(taskQuery.taskAssignee(index.getId().toString()) + .orderByTaskCreateTime().desc().count()); + taskDtoList.addAll(tasks2TaskDtos(list)); + }); + return completableFuture; + }).collect(Collectors.toList()); + CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[completableFutureList.size()])).join(); Page page = new Page(curPage, limit); int j = Math.min(curPage * limit, taskDtoList.size()); if (taskDtoList.isEmpty()) { @@ -180,7 +194,7 @@ public class ActTaskService extends BaseServiceImpl { ArrayList recordLists = new ArrayList<>(); recordLists.addAll(taskDtoList.stream().distinct().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList())); page.setRecords(recordLists); - page.setTotal(taskDtoList.stream().distinct().count()); + page.setTotal(count.stream().mapToLong(index -> index.longValue()).sum()); } return page; } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java index 993fd7a8..2ac3b9a9 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java @@ -14,6 +14,7 @@ import io.renren.modules.security.user.UserDetail; import io.renren.modules.sys.dao.SysDeptDao; import io.renren.modules.sys.dao.SysRegionDao; import io.renren.modules.sys.dao.SysUserDao; +import io.renren.modules.sys.dto.SysRoleDTO; import io.renren.modules.sys.dto.SysUserDTO; import io.renren.modules.sys.entity.SysDeptEntity; import io.renren.modules.sys.entity.SysRegionEntity; @@ -21,12 +22,9 @@ import io.renren.modules.sys.entity.SysUserEntity; import io.renren.modules.sys.enums.JhDeptEnum; import io.renren.modules.sys.enums.JhDeptsEnum; import io.renren.modules.sys.enums.SuperAdminEnum; -import io.renren.modules.sys.service.SysDeptService; -import io.renren.modules.sys.service.SysRoleUserService; -import io.renren.modules.sys.service.SysUserPostService; -import io.renren.modules.sys.service.SysUserService; -import org.apache.commons.lang3.StringUtils; +import io.renren.modules.sys.service.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -56,6 +54,11 @@ public class SysUserServiceImpl extends BaseServiceImpl page(Map params) { @@ -84,7 +87,10 @@ public class SysUserServiceImpl extends BaseServiceImpl entityList = baseDao.getList(params); return ConvertUtils.sourceToTarget(entityList, SysUserDTO.class); @@ -198,11 +204,11 @@ public class SysUserServiceImpl extends BaseServiceImpl deptList = JhDeptEnum.getAllToList(); int size = deptList.size(); - try{ + try { ExecutorService executorService = Executors.newSingleThreadExecutor(); executorService.execute(new Runnable() { @Override @@ -212,33 +218,33 @@ public class SysUserServiceImpl extends BaseServiceImpl set = map1.keySet(); String mName = ""; - for(String s:set){ + for (String s : set) { mName = s; } - String key = mName;//区名,“即墨区” + String key = mName;//区名,“即墨区” - String[] ouStr = (String[])map1.get(key); + String[] ouStr = (String[]) map1.get(key); - for(String ou:ouStr){ - String OU = ou+","+"OU="+mName; + for (String ou : ouStr) { + String OU = ou + "," + "OU=" + mName; LdapContext ldapContext = jhlDAPTool.LDAP_connect(OU); - List> lists = jhlDAPTool.readLdap(ldapContext,"(&(OU=*)(ou=*)(!(sAMAccountType=*))(instanceType=4))"); + List> lists = jhlDAPTool.readLdap(ldapContext, "(&(OU=*)(ou=*)(!(sAMAccountType=*))(instanceType=4))"); //Iterator> iterator = lists.iterator(); //给pid pids赋值 if (lists.size() > 0) { - lists.forEach(dept->{//1.遍历每一个map + lists.forEach(dept -> {//1.遍历每一个map String namespace = dept.get("namespace").toString(); //OU=地税局分局,OU=驻区单位,OU=新市北区,DC=qd,DC=gov,DC=cn String[] namespaces = namespace.split(","); //判断namespaces的长度, - for(int i=1;i map = new HashMap<>(); if (dName.equals(lists.get(j).get("name").toString())) { String id = lists.get(j).get("id").toString(); - String pidsOld = dept.get("pids").toString() == ""? "" : (dept.get("pids").toString() + ","); + String pidsOld = dept.get("pids").toString() == "" ? "" : (dept.get("pids").toString() + ","); if (c == 1) { dept.put("pid", id); dept.put("pids", pidsOld + id); @@ -251,91 +257,91 @@ public class SysUserServiceImpl extends BaseServiceImpl{ - l.put("district",distict); + lists.forEach(l -> { + l.put("district", distict); String name = l.get("name").toString(); - if(name.contains("企业") || name.contains("集团") || name.contains("公司")){ - l.put("type",4); - }else{ - l.put("type",3); + if (name.contains("企业") || name.contains("集团") || name.contains("公司")) { + l.put("type", 4); + } else { + l.put("type", 3); } }); break; case "青岛市级": districtName = "青岛市"; distict = getDistict(districtName); - lists.forEach(l->{ - l.put("district",distict); - l.put("type",2); + lists.forEach(l -> { + l.put("district", distict); + l.put("type", 2); }); break; case "莱西市用户": districtName = "莱西市"; distict = getDistict(districtName); - lists.forEach(l->{ - l.put("district",distict); + lists.forEach(l -> { + l.put("district", distict); String name = l.get("name").toString(); - if(name.contains("企业") || name.contains("集团") || name.contains("公司")){ - l.put("type",4); - }else{ - l.put("type",3); + if (name.contains("企业") || name.contains("集团") || name.contains("公司")) { + l.put("type", 4); + } else { + l.put("type", 3); } }); break; case "黄岛区": districtName = "西海岸新区"; distict = getDistict(districtName); - lists.forEach(l->{ - l.put("district",distict); + lists.forEach(l -> { + l.put("district", distict); String name = l.get("name").toString(); - if(name.contains("企业") || name.contains("集团") || name.contains("公司")){ - l.put("type",4); - }else{ - l.put("type",3); + if (name.contains("企业") || name.contains("集团") || name.contains("公司")) { + l.put("type", 4); + } else { + l.put("type", 3); } }); break; case "市直企业": distict = getDistict("青岛市"); - lists.forEach(l->{ - l.put("district",distict); - l.put("type",4); + lists.forEach(l -> { + l.put("district", distict); + l.put("type", 4); }); break; case "市直机关": distict = getDistict("青岛市"); - lists.forEach(l->{ - l.put("district",distict); - l.put("type",2); + lists.forEach(l -> { + l.put("district", distict); + l.put("type", 2); }); break; case "驻青单位": distict = getDistict("山东省"); - lists.forEach(l->{ - l.put("district",distict); - l.put("type",1); + lists.forEach(l -> { + l.put("district", distict); + l.put("type", 1); }); break; default: distict = getDistict(mName); - lists.forEach(l->{ - l.put("district",distict); + lists.forEach(l -> { + l.put("district", distict); String name = l.get("name").toString(); - if(name.contains("企业") || name.contains("集团") || name.contains("公司")){ - l.put("type",4); - }else{ - l.put("type",3); + if (name.contains("企业") || name.contains("集团") || name.contains("公司")) { + l.put("type", 4); + } else { + l.put("type", 3); } }); } - lists.forEach(list->{//如果有该ID和name,目前暂不处理,,否则插入 + lists.forEach(list -> {//如果有该ID和name,目前暂不处理,,否则插入 SysDeptEntity dept = sysDeptDao.getById(Long.valueOf(list.get("id").toString())); SysDeptEntity deptNew = new SysDeptEntity(); @@ -345,7 +351,7 @@ public class SysUserServiceImpl extends BaseServiceImpl deptList = JhDeptsEnum.getAllToList(); int size = deptList.size(); @@ -375,31 +381,31 @@ public class SysUserServiceImpl extends BaseServiceImpl maps = jhlDAPTool.readLdap(ldapContext); if (maps.size() > 0) { - maps.forEach(m-> { + maps.forEach(m -> { //根据username判断 - if(m.get(("username")) != null){ + if (m.get(("username")) != null) { String userName = m.get("username").toString(); SysUserEntity user = sysUserDao.getUserByName(userName); - if(user == null){//用户表中没有该用户,插入 + if (user == null) {//用户表中没有该用户,插入 SysUserEntity newUser = new SysUserEntity(); newUser.setUsername(userName); newUser.setSuperAdmin(0); - newUser.setGuid(m.get("guid") == null ? "":m.get("guid").toString()); - newUser.setId(Long.valueOf(m.get("id") == null ? "0":m.get("id").toString())); - newUser.setRealName(m.get("real_name") == null ?"":m.get("real_name").toString()); - newUser.setEmail(m.get("email") == null ?"":m.get("email").toString()); - newUser.setMobile(m.get("mobile") == null ?"":m.get("mobile").toString()); + newUser.setGuid(m.get("guid") == null ? "" : m.get("guid").toString()); + newUser.setId(Long.valueOf(m.get("id") == null ? "0" : m.get("id").toString())); + newUser.setRealName(m.get("real_name") == null ? "" : m.get("real_name").toString()); + newUser.setEmail(m.get("email") == null ? "" : m.get("email").toString()); + newUser.setMobile(m.get("mobile") == null ? "" : m.get("mobile").toString()); newUser.setStatus(1);//账号状态 1正常 0停用 //给dept_id赋值 - String deptNames = m.get("distinguishedName") == null ? "":m.get("distinguishedName").toString(); - if(deptNames == null){ + String deptNames = m.get("distinguishedName") == null ? "" : m.get("distinguishedName").toString(); + if (deptNames == null) { newUser.setDeptId(0L); - }else{ + } else { String[] deptArray = deptNames.split(","); - String dept,deptFather; + String dept, deptFather; dept = deptArray[1]; deptFather = deptArray[2]; - long id = getDeptId(dept.substring(3,dept.length()),deptFather.substring(3,deptFather.length())); + long id = getDeptId(dept.substring(3, dept.length()), deptFather.substring(3, deptFather.length())); newUser.setDeptId(id); sysUserDao.insert(newUser); } @@ -417,27 +423,28 @@ public class SysUserServiceImpl extends BaseServiceImpl regionWrapper = new QueryWrapper<>(); - regionWrapper.eq("name",name); + regionWrapper.eq("name", name); SysRegionEntity region = regionDao.selectOne(regionWrapper); return region; } - public long getDeptId(String deptName,String fatherDeptName){ + + public long getDeptId(String deptName, String fatherDeptName) { QueryWrapper deptWrapper = new QueryWrapper<>(); - deptWrapper.eq("name",deptName); + deptWrapper.eq("name", deptName); List deptList = sysDeptDao.selectList(deptWrapper); - if(deptList.size() == 0){ + if (deptList.size() == 0) { return 0; - }else if(deptList.size() == 1){ + } else if (deptList.size() == 1) { return deptList.get(0).getId(); - }else{//出现多个相同的deptname,根据他们的父级来确定 + } else {//出现多个相同的deptname,根据他们的父级来确定 AtomicLong newId = new AtomicLong(); - deptList.forEach(dept->{ + deptList.forEach(dept -> { long fatherId = dept.getPid();//获取其中一个的父级ID SysDeptEntity fatherEntity = sysDeptDao.getById(fatherId);//根据父级ID查询管理部门 - if(fatherEntity != null && fatherEntity.getName().equals(fatherDeptName)){//如果该管理部门的名称等于传进来的父级名称,那么这条dept就是我们需要的 - if(fatherEntity.getId() == fatherId){//如果父级ID等于 + if (fatherEntity != null && fatherEntity.getName().equals(fatherDeptName)) {//如果该管理部门的名称等于传进来的父级名称,那么这条dept就是我们需要的 + if (fatherEntity.getId() == fatherId) {//如果父级ID等于 newId.set(dept.getId()); } } @@ -446,13 +453,13 @@ public class SysUserServiceImpl extends BaseServiceImpl regionWrapper = new QueryWrapper<>(); - regionWrapper.eq("name",deptName); + regionWrapper.eq("name", deptName); SysRegionEntity entity = regionDao.selectOne(regionWrapper); if (entity == null) { return 0L; - }else{ + } else { return entity.getId(); } } diff --git a/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml b/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml index 992db2ea..f1569b2c 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysUserDao.xml @@ -28,6 +28,9 @@ #{id} + + AND EXISTS(SELECT 1 FROM sys_role_user WHERE sys_role_user.user_id = t1.id AND sys_role_user.role_id = #{role_id}) +