完善单随机、双随机逻辑
This commit is contained in:
parent
4c8ea7b5d5
commit
4827ec0b3e
@ -152,4 +152,13 @@ public interface IEnterpriseOfGridOperatorDao {
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<EnterpriseOfGridOperatorDTO> listSimple(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 企业ID列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listEnterpriseId(Map<String, Object> params) throws SearchException;
|
||||
}
|
||||
|
@ -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<EnterpriseDTO> listEnterprise(Map<String, Object> 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<String> enterpriseIds = enterpriseOfGridOperatorService.listEnterpriseId(params);
|
||||
if (enterpriseIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
params.put("enterpriseIds", enterpriseIds);
|
||||
}
|
||||
List<EnterpriseDTO> srcEnterpriseDTO = enterpriseDao.listEnterprise(params);
|
||||
return ArrayListUtil.deepClone(srcEnterpriseDTO, EnterpriseDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -235,4 +235,28 @@ public interface IEnterpriseOfGridOperatorService {
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<EnterpriseOfGridOperatorDTO> listSimple(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 企业ID列表
|
||||
*
|
||||
* @param userIds 用户ID列表
|
||||
* @return
|
||||
*/
|
||||
List<String> listEnterpriseIdOfUserIds(List<String> userIds);
|
||||
|
||||
/**
|
||||
* 企业ID列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<String> listEnterpriseId(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 企业ID列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return
|
||||
*/
|
||||
List<String> listEnterpriseIdByUserId(String userId);
|
||||
}
|
||||
|
@ -276,6 +276,25 @@ public class EnterpriseOfGridOperatorServiceImpl extends BaseService implements
|
||||
return enterpriseOfGridOperatorDao.listSimple(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listEnterpriseIdOfUserIds(List<String> userIds) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("userIds", userIds);
|
||||
return listEnterpriseId(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listEnterpriseId(Map<String, Object> params) {
|
||||
return enterpriseOfGridOperatorDao.listEnterpriseId(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listEnterpriseIdByUserId(String userId) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("userId", userId);
|
||||
return listEnterpriseId(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化未认领地区
|
||||
*
|
||||
|
@ -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<EnterpriseDTO> enterpriseDTOs = enterpriseService.listEnterprise(params);
|
||||
if (enterpriseDTOs.isEmpty()) {
|
||||
throw new SearchException("未随机到任何企业");
|
||||
return new ArrayList<>();
|
||||
// throw new SearchException("未随机到任何企业");
|
||||
}
|
||||
if (enterpriseDTOs.size() <= randomCount) {
|
||||
|
||||
List<String> userIds = (List<String>) params.get("userIds");
|
||||
List<UserResourceBO> 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<String> 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<String, EnterpriseDTO> randomEnterpriseMap = new HashMap<>(enterpriseDTOs.size() * 2);
|
||||
Random random = new Random();
|
||||
Map<Integer, EnterpriseDTO> 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<String> 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<EnterpriseDTO> resultEnterpriseDTOs = new ArrayList<>();
|
||||
for (Map.Entry<Integer, EnterpriseDTO> kv : randomEnterpriseMap.entrySet()) {
|
||||
for (Map.Entry<String, EnterpriseDTO> kv : randomEnterpriseMap.entrySet()) {
|
||||
resultEnterpriseDTOs.add(kv.getValue());
|
||||
}
|
||||
return resultEnterpriseDTOs;
|
||||
@ -234,9 +294,21 @@ public class TaskCheckServiceImpl extends BaseService implements ITaskCheckServi
|
||||
public List<EnterpriseDTO> listDoubleRandom(Integer randomCount, Map<String, Object> params) throws SearchException {
|
||||
Map<String, Object> newParams = getHashMap(16);
|
||||
newParams.putAll(params);
|
||||
List<EnterpriseDTO> enterprises = listRandomEnterprise(randomCount, newParams);
|
||||
List<GridPersonnelDTO> gridPersonnelDTOs = listRandomGridPersonnel(randomCount, params);
|
||||
setCheckUser(enterprises, gridPersonnelDTOs);
|
||||
List<EnterpriseDTO> enterprises = null;
|
||||
if (params.get("selectedUserIds") == null) {
|
||||
// 没有选择 处理任务的人员,人员和企业全部打乱,最终检查的企业数量为随机的数量
|
||||
enterprises = listRandomEnterprise(randomCount, newParams);
|
||||
List<GridPersonnelDTO> gridPersonnelDTOs = listRandomGridPersonnel(randomCount, params);
|
||||
setCheckUser(enterprises, gridPersonnelDTOs);
|
||||
} else {
|
||||
// 选择了处理任务的人员,就对每个任务出来人均随机分配,最终检查企业数量为 随机数量 * 检查人员
|
||||
// 例如5个人员,随机5个企业,那么最终每个人都会随机到5个企业,总和为25
|
||||
List<String> 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<EnterpriseDTO> enterprises, List<String> userIds, int randomCount) {
|
||||
List<UserResourceBO> 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());
|
||||
}
|
||||
}
|
||||
// 清除没有分配的企业
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -684,4 +684,34 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 企业ID列表 -->
|
||||
<select id="listEnterpriseId" parameterType="map" resultType="java.lang.String">
|
||||
SELECT
|
||||
enterprise_id
|
||||
FROM
|
||||
gen_enterprise_of_grid_operator
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="userId != null and userId != ''">
|
||||
AND
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
<if test="userIds != null and userIds.size > 0">
|
||||
AND
|
||||
user_id IN
|
||||
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
||||
#{userIds[${index}]}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="enterpriseIds != null and enterpriseIds.size > 0">
|
||||
AND
|
||||
enterprise_id IN
|
||||
<foreach collection="enterpriseIds" index="index" open="(" separator="," close=")">
|
||||
#{enterpriseIds[${index}]}
|
||||
</foreach>
|
||||
</if>
|
||||
GROUP BY
|
||||
enterprise_id
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -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 = '';
|
||||
|
@ -9,6 +9,11 @@
|
||||
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
||||
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
<style>
|
||||
.selected-user {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid layui-anim layui-anim-fadein">
|
||||
@ -48,6 +53,18 @@
|
||||
<input type="radio" name="taskTypeSub" value="2" title="限时任务" lay-filter="taskTypeSubFilter">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">选择人员(点击下方空白处打开人员选择)</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="hidden" id="selectedUserIds" name="selectedUserIds">
|
||||
<div id="selectedUserIdsTemplateBox" style="border: 1px solid #e6e6e6; cursor: pointer; padding: 15px 15px 0 15px" lay-filter="selectedUserTemplateBox"></div>
|
||||
<script id="selectedUserIdsTemplate" type="text/html">
|
||||
{{# for(var i = 0, item; item = d[i++];) { }}
|
||||
<button type="button" class="layui-btn layui-btn-sm selected-user">{{item.userName}}</button>
|
||||
{{# } }}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div id="startEndTimeBox" class="layui-row" style="display: none;">
|
||||
<div class="layui-col-md6 layui-col-sm6 layui-col-xs6">
|
||||
<div class="layui-form-item">
|
||||
@ -316,8 +333,8 @@
|
||||
if(!taskType || taskType == '1') {
|
||||
cols[0].unshift({type:'checkbox', fixed: 'left'});
|
||||
}
|
||||
// 双随机
|
||||
if(taskType == '3') {
|
||||
// 单随机选人或者双随机
|
||||
if( (taskType == '2' && $('#selectedUserIds').val()) || taskType == '3') {
|
||||
addCheckUser(cols[0]);
|
||||
}
|
||||
if(checkItemListType && checkItemListType == '2') {
|
||||
@ -341,7 +358,8 @@
|
||||
area3: $('#area3').val(),
|
||||
area4: $('#area4').val(),
|
||||
area5: $('#area5').val(),
|
||||
pollutionFactors: pollutionFactorArray.toString()
|
||||
pollutionFactors: pollutionFactorArray.toString(),
|
||||
selectedUserIds: $('#selectedUserIds').val()
|
||||
},
|
||||
limit: 20,
|
||||
limits: [20, 40, 60, 80, 100, 200],
|
||||
@ -674,6 +692,35 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#selectedUserIdsTemplateBox').on('click', function() {
|
||||
top.dialog.dialogData.selectedUserIds = $('#selectedUserIds').val();
|
||||
top.dialog.open({
|
||||
url: top.restAjax.path('route/user/departmentuser', []),
|
||||
title: '选择组织部门人员',
|
||||
width: '500px',
|
||||
height: '500px',
|
||||
onClose: function() {
|
||||
var selectedUsers = top.dialog.dialogData.selectedDepartmentUsers;
|
||||
if(selectedUsers != null && selectedUsers.length > 0) {
|
||||
var selectedUserIds = '';
|
||||
for (var i = 0, item; item = selectedUsers[i++];) {
|
||||
if ('' != selectedUserIds) {
|
||||
selectedUserIds += '_';
|
||||
}
|
||||
selectedUserIds += item.userId;
|
||||
}
|
||||
$('#selectedUserIds').val(selectedUserIds)
|
||||
} else {
|
||||
$('#selectedUserIds').val('');
|
||||
}
|
||||
laytpl(document.getElementById('selectedUserIdsTemplate').innerHTML).render(selectedUsers, function(html) {
|
||||
document.getElementById('selectedUserIdsTemplateBox').innerHTML = html;
|
||||
});
|
||||
initTable();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$('.close').on('click', function() {
|
||||
closeBox();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user