|
|
|
@ -277,18 +277,15 @@ public class RoleServiceImpl implements RoleService { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer addWarehouseVisiblePermission(Map<String, Object> map) { |
|
|
|
public Integer setWarehouseVisiblePermission(Map<String, Object> map) { |
|
|
|
// 获取当前赋值的权限类型
|
|
|
|
String type = (String) map.get("type"); |
|
|
|
// 定义返回结果
|
|
|
|
Integer result = 0; |
|
|
|
// 用于插入权限列表
|
|
|
|
Map<String, Object> paramForInsert = new HashMap<>(); |
|
|
|
paramForInsert.put("userId", map.get("userId")); |
|
|
|
paramForInsert.put("time", System.currentTimeMillis()); |
|
|
|
paramForInsert.put("depositoryIdList", map.get("depositoryIds")); |
|
|
|
paramForInsert.put("state", 1); |
|
|
|
List<Object> userIds = (List<Object>) map.get("userIds"); |
|
|
|
|
|
|
|
|
|
|
|
if ("person".equals(type)) { |
|
|
|
// 如果是对人员赋权
|
|
|
|
paramForInsert.put("type", 1); |
|
|
|
@ -298,14 +295,102 @@ public class RoleServiceImpl implements RoleService { |
|
|
|
} else { |
|
|
|
throw new MyException("未知参数错误"); |
|
|
|
} |
|
|
|
// 获取当前要处理的数量
|
|
|
|
Integer count = ObjectFormatUtil.toInteger(map.get("count")); |
|
|
|
|
|
|
|
List<Object> userIds = (List<Object>) map.get("userIds"); |
|
|
|
paramForInsert.put("uidList", userIds); |
|
|
|
// 获取当前要处理用于及其仓库的数量
|
|
|
|
Integer countByCondition = roleMapper.findWarehouseVisiblePermissionCountByCondition(paramForInsert); |
|
|
|
if (countByCondition > count) { |
|
|
|
// 当前数量小于已存在的数量,则代表权限删除
|
|
|
|
result = countByCondition - delWarehouseVisiblePermission(map); |
|
|
|
} else { |
|
|
|
paramForInsert.put("depositoryIdList", map.get("depositoryIds")); |
|
|
|
paramForInsert.put("userId", map.get("userId")); |
|
|
|
paramForInsert.put("time", System.currentTimeMillis()); |
|
|
|
// 用于查询当前可见的仓库id数量
|
|
|
|
Map<String, Object> paramForCount = new HashMap<>(); |
|
|
|
paramForCount.put("type", paramForInsert.get("type")); |
|
|
|
for (Object userId : userIds |
|
|
|
) { |
|
|
|
paramForInsert.put("uid", userId); |
|
|
|
result += roleMapper.addWarehouseVisiblePermission(paramForInsert); |
|
|
|
paramForCount.put("uid", userId); |
|
|
|
Integer paramCount = roleMapper.findDepositoryIDCountForWarehouseVisiblePermissionByCondition(paramForCount); |
|
|
|
result += (roleMapper.addWarehouseVisiblePermission(paramForInsert) - paramCount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用于删除权限 |
|
|
|
* |
|
|
|
* @param map 待删除数据 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Integer delWarehouseVisiblePermission(Map<String, Object> map) { |
|
|
|
// 获取当前赋值的权限类型
|
|
|
|
|
|
|
|
Map<String, Object> paramForDelete = new HashMap<>(); |
|
|
|
Integer integer = 0; |
|
|
|
String type = (String) map.get("type"); |
|
|
|
if ("person".equals(type)) { |
|
|
|
// 如果是对人员赋权
|
|
|
|
paramForDelete.put("type", 1); |
|
|
|
} else if ("post".equals(type)) { |
|
|
|
// 如果是对岗位赋权
|
|
|
|
paramForDelete.put("type", 2); |
|
|
|
} else { |
|
|
|
throw new MyException("未知参数错误"); |
|
|
|
} |
|
|
|
List<Object> userIds = (List<Object>) map.get("userIds"); |
|
|
|
List<Integer> depositoryIds = (List<Integer>) map.get("depositoryIds"); |
|
|
|
if (depositoryIds.size() == 0) { |
|
|
|
// 如果是要删除所有的
|
|
|
|
|
|
|
|
paramForDelete.put("uidList", userIds); |
|
|
|
// 删除当前所有的权限
|
|
|
|
integer = roleMapper.delWarehouseVisiblePermissionByCondition(paramForDelete); |
|
|
|
} else { |
|
|
|
// 如果不是所有
|
|
|
|
for (Object uid : userIds |
|
|
|
) { |
|
|
|
paramForDelete.put("uid", uid); |
|
|
|
// 获取当前用户所拥有的权限
|
|
|
|
List<Integer> depositoryIdList = roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(paramForDelete); |
|
|
|
// 获取当前已拥有的与新拥有的差集
|
|
|
|
depositoryIdList.removeAll(depositoryIds); |
|
|
|
paramForDelete.put("depositoryIdList", depositoryIdList); |
|
|
|
integer += roleMapper.delWarehouseVisiblePermissionByCondition(paramForDelete); |
|
|
|
} |
|
|
|
} |
|
|
|
return integer; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据调剂获取在可视范围内的仓库id |
|
|
|
* |
|
|
|
* @param map 待查询调剂 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<Integer> findDepositoryIdForWarehouseVisiblePermissionByCondition(Map<String, Object> map) { |
|
|
|
String type = (String) map.get("type"); |
|
|
|
if ("person".equals(type)) { |
|
|
|
// 如果是对人员赋权
|
|
|
|
map.put("type", 1); |
|
|
|
} else if ("post".equals(type)) { |
|
|
|
// 如果是对岗位赋权
|
|
|
|
map.put("type", 2); |
|
|
|
} else { |
|
|
|
throw new MyException("未知参数错误"); |
|
|
|
} |
|
|
|
return roleMapper.findDepositoryIdForWarehouseVisiblePermissionByCondition(map); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前仓库的子仓库 |
|
|
|
|