From 4827ec0b3e4532a9ef14bf2bc7c99491c4549b04 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Wed, 3 Mar 2021 18:22:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=95=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E3=80=81=E5=8F=8C=E9=9A=8F=E6=9C=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IEnterpriseOfGridOperatorDao.java | 9 ++ .../impl/EnterpriseServiceImpl.java | 15 +- .../IEnterpriseOfGridOperatorService.java | 24 ++++ .../EnterpriseOfGridOperatorServiceImpl.java | 19 +++ .../v2/impl/TaskCheckServiceImpl.java | 129 ++++++++++++++++-- .../enterpriseofgridoperator-mapper.xml | 30 ++++ .../route/taskcheck/v2/list-taskcheck.html | 2 +- .../route/taskcheck/v2/save-taskcheck.html | 53 ++++++- 8 files changed, 265 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/cm/inspection/dao/enterpriseofgridoperator/IEnterpriseOfGridOperatorDao.java b/src/main/java/com/cm/inspection/dao/enterpriseofgridoperator/IEnterpriseOfGridOperatorDao.java index 18c406b..018a103 100644 --- a/src/main/java/com/cm/inspection/dao/enterpriseofgridoperator/IEnterpriseOfGridOperatorDao.java +++ b/src/main/java/com/cm/inspection/dao/enterpriseofgridoperator/IEnterpriseOfGridOperatorDao.java @@ -152,4 +152,13 @@ public interface IEnterpriseOfGridOperatorDao { * @throws SearchException */ List listSimple(Map params) throws SearchException; + + /** + * 企业ID列表 + * + * @param params + * @return + * @throws SearchException + */ + List listEnterpriseId(Map params) throws SearchException; } diff --git a/src/main/java/com/cm/inspection/service/enterprise/impl/EnterpriseServiceImpl.java b/src/main/java/com/cm/inspection/service/enterprise/impl/EnterpriseServiceImpl.java index e36e64b..41c9a49 100644 --- a/src/main/java/com/cm/inspection/service/enterprise/impl/EnterpriseServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/enterprise/impl/EnterpriseServiceImpl.java @@ -11,6 +11,7 @@ import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; import com.cm.common.result.SuccessResultList; import com.cm.common.token.app.AppTokenManager; +import com.cm.common.utils.ArrayListUtil; import com.cm.common.utils.HashMapUtil; import com.cm.common.utils.UUIDUtil; import com.cm.inspection.dao.enterprise.IEnterpriseDao; @@ -430,6 +431,7 @@ public class EnterpriseServiceImpl extends BaseService implements IEnterpriseSer @Override public List listEnterprise(Map params) throws SearchException { + // 污染因子条件 if (params.get("pollutionFactors") != null) { String pollutionFactors = params.get("pollutionFactors").toString(); if (!StringUtils.isBlank(pollutionFactors)) { @@ -445,7 +447,18 @@ public class EnterpriseServiceImpl extends BaseService implements IEnterpriseSer params.put("enterpriseIds", enterpriseIds); } } - return enterpriseDao.listEnterprise(params); + // 网格员 + if (params.get("selectedUserIds") != null) { + String selectedUserIds = params.get("selectedUserIds").toString(); + params.put("userIds", Arrays.asList(selectedUserIds.split("\\_"))); + List enterpriseIds = enterpriseOfGridOperatorService.listEnterpriseId(params); + if (enterpriseIds.isEmpty()) { + return new ArrayList<>(); + } + params.put("enterpriseIds", enterpriseIds); + } + List srcEnterpriseDTO = enterpriseDao.listEnterprise(params); + return ArrayListUtil.deepClone(srcEnterpriseDTO, EnterpriseDTO.class); } @Override diff --git a/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/IEnterpriseOfGridOperatorService.java b/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/IEnterpriseOfGridOperatorService.java index 1321715..f59b070 100644 --- a/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/IEnterpriseOfGridOperatorService.java +++ b/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/IEnterpriseOfGridOperatorService.java @@ -235,4 +235,28 @@ public interface IEnterpriseOfGridOperatorService { * @throws SearchException */ List listSimple(Map params) throws SearchException; + + /** + * 企业ID列表 + * + * @param userIds 用户ID列表 + * @return + */ + List listEnterpriseIdOfUserIds(List userIds); + + /** + * 企业ID列表 + * + * @param params + * @return + */ + List listEnterpriseId(Map params); + + /** + * 企业ID列表 + * + * @param userId 用户ID + * @return + */ + List listEnterpriseIdByUserId(String userId); } diff --git a/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/impl/EnterpriseOfGridOperatorServiceImpl.java b/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/impl/EnterpriseOfGridOperatorServiceImpl.java index 3a6af16..56f7bd8 100644 --- a/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/impl/EnterpriseOfGridOperatorServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/enterpriseofgridoperator/impl/EnterpriseOfGridOperatorServiceImpl.java @@ -276,6 +276,25 @@ public class EnterpriseOfGridOperatorServiceImpl extends BaseService implements return enterpriseOfGridOperatorDao.listSimple(params); } + @Override + public List listEnterpriseIdOfUserIds(List userIds) { + Map params = getHashMap(2); + params.put("userIds", userIds); + return listEnterpriseId(params); + } + + @Override + public List listEnterpriseId(Map params) { + return enterpriseOfGridOperatorDao.listEnterpriseId(params); + } + + @Override + public List listEnterpriseIdByUserId(String userId) { + Map params = getHashMap(2); + params.put("userId", userId); + return listEnterpriseId(params); + } + /** * 初始化未认领地区 * diff --git a/src/main/java/com/cm/inspection/service/taskcheck/v2/impl/TaskCheckServiceImpl.java b/src/main/java/com/cm/inspection/service/taskcheck/v2/impl/TaskCheckServiceImpl.java index 6f41151..58eea35 100644 --- a/src/main/java/com/cm/inspection/service/taskcheck/v2/impl/TaskCheckServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/taskcheck/v2/impl/TaskCheckServiceImpl.java @@ -45,6 +45,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * When you feel like quitting. Think about why you started @@ -185,21 +186,80 @@ public class TaskCheckServiceImpl extends BaseService implements ITaskCheckServi params.put("isLogOff", 0); List enterpriseDTOs = enterpriseService.listEnterprise(params); if (enterpriseDTOs.isEmpty()) { - throw new SearchException("未随机到任何企业"); + return new ArrayList<>(); + // throw new SearchException("未随机到任何企业"); } - if (enterpriseDTOs.size() <= randomCount) { + + List userIds = (List) params.get("userIds"); + List userResourceBOs = null; + if (userIds != null) { + // 去重 + userIds = new ArrayList<>(new HashSet<>(userIds)); + userResourceBOs = userService.listUserResourceByIds(userIds); + if (userResourceBOs.isEmpty()) { + return new ArrayList<>(); + } + } + // 企业数量小于随机数量,返回全部企业列表 + if (enterpriseDTOs.size() < randomCount) { + for (UserResourceBO userResourceBO : userResourceBOs) { + List enterpriseIds = enterpriseOfGridOperatorService.listEnterpriseIdByUserId(userResourceBO.getUserId()); + for (String enterpriseId : enterpriseIds) { + for (EnterpriseDTO enterpriseDTO : enterpriseDTOs) { + if (StringUtils.equals(enterpriseId, enterpriseDTO.getEnterpriseId())) { + enterpriseDTO.setCheckUserId(userResourceBO.getUserId()); + enterpriseDTO.setCheckUserName(userResourceBO.getUserName()); + } + } + } + } return enterpriseDTOs; } + // 企业数量大于随机数量,按随机逻辑执行 + Map randomEnterpriseMap = new HashMap<>(enterpriseDTOs.size() * 2); Random random = new Random(); - Map randomEnterpriseMap = new HashMap<>(enterpriseDTOs.size() * 2); - while (randomEnterpriseMap.size() < randomCount) { - int enterpriseIndex = random.nextInt(enterpriseDTOs.size()); - if (randomEnterpriseMap.get(enterpriseIndex) == null) { - randomEnterpriseMap.put(enterpriseIndex, enterpriseDTOs.get(enterpriseIndex)); + if (userResourceBOs != null) { + // 如果选择了人员,随机数量就是每个人的随机数量,比如3个人,随机数是2,那么就是每个人都随机两个企业,最终就是6条 + for (int i = 0; i < userResourceBOs.size(); i++) { + UserResourceBO userResourceBO = userResourceBOs.get(i); + // 如果人员的企业没有达到随机数量,以企业数量为准 + List enterpriseIds = enterpriseOfGridOperatorService.listEnterpriseIdByUserId(userResourceBO.getUserId()); + if (enterpriseIds.size() < randomCount) { + for (String enterpriseId : enterpriseIds) { + for (EnterpriseDTO enterpriseDTO : enterpriseDTOs) { + if (StringUtils.equals(enterpriseId, enterpriseDTO.getEnterpriseId())) { + enterpriseDTO.setCheckUserId(userResourceBO.getUserId()); + enterpriseDTO.setCheckUserName(userResourceBO.getUserName()); + randomEnterpriseMap.put(enterpriseId, enterpriseDTO); + } + } + } + } else { + int currentRandom = 0; + while (currentRandom < randomCount) { + int enterpriseIndex = random.nextInt(enterpriseDTOs.size()); + EnterpriseDTO enterpriseDTO = enterpriseDTOs.get(enterpriseIndex); + if (randomEnterpriseMap.get(enterpriseDTO.getEnterpriseId()) == null) { + enterpriseDTO.setCheckUserId(userResourceBO.getUserId()); + enterpriseDTO.setCheckUserName(userResourceBO.getUserName()); + randomEnterpriseMap.put(enterpriseDTO.getEnterpriseId(), enterpriseDTO); + currentRandom++; + } + } + } + } + } else { + // 如果没有选择人员,随机数是多少,就随机多少 + while (randomEnterpriseMap.size() < randomCount) { + Integer enterpriseIndex = random.nextInt(enterpriseDTOs.size()); + String enterpriseIndexString = enterpriseIndex.toString(); + if (randomEnterpriseMap.get(enterpriseIndexString) == null) { + randomEnterpriseMap.put(enterpriseIndexString, enterpriseDTOs.get(enterpriseIndex)); + } } } List resultEnterpriseDTOs = new ArrayList<>(); - for (Map.Entry kv : randomEnterpriseMap.entrySet()) { + for (Map.Entry kv : randomEnterpriseMap.entrySet()) { resultEnterpriseDTOs.add(kv.getValue()); } return resultEnterpriseDTOs; @@ -234,9 +294,21 @@ public class TaskCheckServiceImpl extends BaseService implements ITaskCheckServi public List listDoubleRandom(Integer randomCount, Map params) throws SearchException { Map newParams = getHashMap(16); newParams.putAll(params); - List enterprises = listRandomEnterprise(randomCount, newParams); - List gridPersonnelDTOs = listRandomGridPersonnel(randomCount, params); - setCheckUser(enterprises, gridPersonnelDTOs); + List enterprises = null; + if (params.get("selectedUserIds") == null) { + // 没有选择 处理任务的人员,人员和企业全部打乱,最终检查的企业数量为随机的数量 + enterprises = listRandomEnterprise(randomCount, newParams); + List gridPersonnelDTOs = listRandomGridPersonnel(randomCount, params); + setCheckUser(enterprises, gridPersonnelDTOs); + } else { + // 选择了处理任务的人员,就对每个任务出来人均随机分配,最终检查企业数量为 随机数量 * 检查人员 + // 例如5个人员,随机5个企业,那么最终每个人都会随机到5个企业,总和为25 + List userIds = new ArrayList(Arrays.asList(params.get("selectedUserIds").toString().split("\\_"))); + userIds.stream().distinct().collect(Collectors.toList()); + newParams.remove("selectedUserIds"); + enterprises = listRandomEnterprise(randomCount * userIds.size(), newParams); + setCheckUser(enterprises, userIds, randomCount); + } return enterprises; } @@ -452,4 +524,39 @@ public class TaskCheckServiceImpl extends BaseService implements ITaskCheckServi } } + /** + * 依次项企业添加 处理用户,如果 处理用户 不足,删除多余企业 + * + * @param enterprises + * @param userIds + * @param randomCount 随机数量 + */ + private void setCheckUser(List enterprises, List userIds, int randomCount) { + List userResourceBOs = userService.listUserResourceByIds(userIds); + if (userResourceBOs.isEmpty()) { + enterprises.clear(); + return; + } + if (enterprises.size() < randomCount) { + // 企业数量小于随机数量,说明一个人的量都不够,这时分配给第一个人 + UserResourceBO userResourceBO = userResourceBOs.get(0); + for (EnterpriseDTO enterpriseDTO : enterprises) { + enterpriseDTO.setCheckUserId(userResourceBO.getUserId()); + enterpriseDTO.setCheckUserName(userResourceBO.getUserName()); + } + } else { + // 企业数量大于等于随机数,依次进行分配,比如随机数为5,按顺序为每个用户分配企业。 + for (int i = 0; i < userResourceBOs.size(); i++) { + UserResourceBO userResourceBO = userResourceBOs.get(i); + for (int j = i * randomCount; j < i * randomCount + randomCount; j++) { + EnterpriseDTO enterpriseDTO = enterprises.get(j); + enterpriseDTO.setCheckUserId(userResourceBO.getUserId()); + enterpriseDTO.setCheckUserName(userResourceBO.getUserName()); + } + } + // 清除没有分配的企业 + } + + } + } diff --git a/src/main/resources/mybatis/mapper/enterpriseofgridoperator/enterpriseofgridoperator-mapper.xml b/src/main/resources/mybatis/mapper/enterpriseofgridoperator/enterpriseofgridoperator-mapper.xml index 3319abe..c941fb9 100644 --- a/src/main/resources/mybatis/mapper/enterpriseofgridoperator/enterpriseofgridoperator-mapper.xml +++ b/src/main/resources/mybatis/mapper/enterpriseofgridoperator/enterpriseofgridoperator-mapper.xml @@ -684,4 +684,34 @@ + + + \ No newline at end of file diff --git a/src/main/resources/static/route/taskcheck/v2/list-taskcheck.html b/src/main/resources/static/route/taskcheck/v2/list-taskcheck.html index a9c24d2..53e7950 100644 --- a/src/main/resources/static/route/taskcheck/v2/list-taskcheck.html +++ b/src/main/resources/static/route/taskcheck/v2/list-taskcheck.html @@ -159,7 +159,7 @@ return '错误'; } }, - {field: 'time', width: 340, title: '开始时间', align:'center', + {field: 'time', width: 340, title: '开始 ~ 结束时间', align:'center', templet: function(row) { var rowData = row.startTime; var result = ''; diff --git a/src/main/resources/static/route/taskcheck/v2/save-taskcheck.html b/src/main/resources/static/route/taskcheck/v2/save-taskcheck.html index 1781afa..cab8784 100644 --- a/src/main/resources/static/route/taskcheck/v2/save-taskcheck.html +++ b/src/main/resources/static/route/taskcheck/v2/save-taskcheck.html @@ -9,6 +9,11 @@ +
@@ -48,6 +53,18 @@
+
+ +
+ +
+ +
+