feat(auth): 人员库授权功能调整
This commit is contained in:
@@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.constraints.*;
|
import jakarta.validation.constraints.*;
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import org.dromara.common.core.domain.TreeNode;
|
||||||
|
import org.dromara.sis.domain.SisAuthRecord;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||||
@@ -73,7 +75,7 @@ public class SisAuthRecordController extends BaseController {
|
|||||||
* 新增授权记录
|
* 新增授权记录
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("sis:authRecord:add")
|
@SaCheckPermission("sis:authRecord:add")
|
||||||
@Log(title = "授权记录", businessType = BusinessType.INSERT)
|
@Log(title = "人员库授权", businessType = BusinessType.INSERT)
|
||||||
@RepeatSubmit()
|
@RepeatSubmit()
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody SisAuthRecordBo bo) {
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody SisAuthRecordBo bo) {
|
||||||
@@ -103,4 +105,24 @@ public class SisAuthRecordController extends BaseController {
|
|||||||
@PathVariable("ids") Long[] ids) {
|
@PathVariable("ids") Long[] ids) {
|
||||||
return toAjax(sisAuthRecordService.deleteWithValidByIds(List.of(ids), true));
|
return toAjax(sisAuthRecordService.deleteWithValidByIds(List.of(ids), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询库id授权的设备
|
||||||
|
*
|
||||||
|
* @param libId 人像库id
|
||||||
|
*/
|
||||||
|
@GetMapping("/authDevice/{libId}")
|
||||||
|
public R<List<SisAuthRecord>> queryAuthDevice(@PathVariable("libId") String libId) {
|
||||||
|
return R.ok(sisAuthRecordService.queryAuthDevice(libId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可授权设备
|
||||||
|
*
|
||||||
|
* @return List<TreeNode < Long>>
|
||||||
|
*/
|
||||||
|
@GetMapping("/authDevice/tree")
|
||||||
|
public R<List<TreeNode<Long>>> tree() {
|
||||||
|
return R.ok(sisAuthRecordService.authDeviceTree());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +0,0 @@
|
|||||||
package org.dromara.sis.domain.bo;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 人像库授权
|
|
||||||
*
|
|
||||||
* @author lxj
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class AuthLibBo {
|
|
||||||
|
|
||||||
@NotNull(message = "人像库id不能为空")
|
|
||||||
private Long libId;
|
|
||||||
|
|
||||||
@NotNull(message = "设备列表不能为空")
|
|
||||||
private List<Long> deviceIds;
|
|
||||||
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
package org.dromara.sis.domain.bo;
|
|
||||||
|
|
||||||
import io.github.linpeilie.annotations.AutoMapper;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.dromara.common.core.validate.AddGroup;
|
|
||||||
import org.dromara.common.core.validate.EditGroup;
|
|
||||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
|
||||||
import org.dromara.sis.domain.SisAuthRecord;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 授权记录业务对象 sis_auth_record
|
|
||||||
*
|
|
||||||
* @author lxj
|
|
||||||
* @since 2025-06-28
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@AutoMapper(target = SisAuthRecord.class, reverseConvertGenerate = false)
|
|
||||||
public class SingleAuthRecordBo extends BaseEntity {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图像库Id
|
|
||||||
*/
|
|
||||||
@NotNull(message = "图像库Id不能为空", groups = {AddGroup.class, EditGroup.class})
|
|
||||||
private Long libId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图像id列表
|
|
||||||
*/
|
|
||||||
@NotNull(message = "图像id列表不能为空", groups = {AddGroup.class, EditGroup.class})
|
|
||||||
private Long imgId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 门禁id列表
|
|
||||||
*/
|
|
||||||
@NotNull(message = "门禁id列表能为空", groups = {AddGroup.class, EditGroup.class})
|
|
||||||
private List<Long> acIds;
|
|
||||||
|
|
||||||
}
|
|
@@ -35,14 +35,8 @@ public class SisAuthRecordBo extends BaseEntity {
|
|||||||
private Long libId;
|
private Long libId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 门禁idList
|
* 授权设备idList
|
||||||
*/
|
*/
|
||||||
@NotEmpty(message = "门禁idList不能为空", groups = {AddGroup.class, EditGroup.class})
|
@NotEmpty(message = "授权设备idList不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
private Collection<Long> acIdList;
|
private Collection<Long> deviceIds;
|
||||||
|
|
||||||
/**
|
|
||||||
* 电梯idList
|
|
||||||
*/
|
|
||||||
@NotEmpty(message = "电梯idList不能为空", groups = {AddGroup.class, EditGroup.class})
|
|
||||||
private Collection<Long> eleIdList;
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package org.dromara.sis.service;
|
package org.dromara.sis.service;
|
||||||
|
|
||||||
|
import org.dromara.common.core.domain.TreeNode;
|
||||||
|
import org.dromara.sis.domain.SisAuthRecord;
|
||||||
import org.dromara.sis.domain.vo.SisAuthRecordVo;
|
import org.dromara.sis.domain.vo.SisAuthRecordVo;
|
||||||
import org.dromara.sis.domain.bo.SisAuthRecordBo;
|
import org.dromara.sis.domain.bo.SisAuthRecordBo;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
@@ -65,4 +67,26 @@ public interface ISisAuthRecordService {
|
|||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询库id授权的设备
|
||||||
|
*
|
||||||
|
* @param libId 人像库id
|
||||||
|
* @return List<SisAuthRecord>
|
||||||
|
*/
|
||||||
|
List<SisAuthRecord> queryAuthDevice(String libId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据人像库id删除授权记录
|
||||||
|
*
|
||||||
|
* @param libId 人像库id
|
||||||
|
*/
|
||||||
|
Boolean deleteByLibId(Long libId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可授权设备树
|
||||||
|
*
|
||||||
|
* @return List<TreeNode<Long>>
|
||||||
|
*/
|
||||||
|
List<TreeNode<Long>> authDeviceTree();
|
||||||
}
|
}
|
||||||
|
@@ -71,4 +71,12 @@ public interface ISisElevatorInfoService {
|
|||||||
* @return 返回电梯列表
|
* @return 返回电梯列表
|
||||||
*/
|
*/
|
||||||
List<SisElevatorInfoVo> queryAll();
|
List<SisElevatorInfoVo> queryAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据查询列表
|
||||||
|
*
|
||||||
|
* @param ids 电梯id
|
||||||
|
* @return 列表
|
||||||
|
*/
|
||||||
|
List<SisElevatorInfoVo> queryListByIds(Collection<Long> ids);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package org.dromara.sis.service.impl;
|
package org.dromara.sis.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import org.dromara.common.core.domain.TreeNode;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
@@ -9,6 +11,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.sis.domain.bo.SisAccessControlBo;
|
||||||
|
import org.dromara.sis.domain.bo.SisElevatorInfoBo;
|
||||||
|
import org.dromara.sis.domain.vo.SisAccessControlVo;
|
||||||
|
import org.dromara.sis.domain.vo.SisElevatorInfoVo;
|
||||||
|
import org.dromara.sis.service.ISisAccessControlService;
|
||||||
|
import org.dromara.sis.service.ISisElevatorInfoService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.dromara.sis.domain.bo.SisAuthRecordBo;
|
import org.dromara.sis.domain.bo.SisAuthRecordBo;
|
||||||
import org.dromara.sis.domain.vo.SisAuthRecordVo;
|
import org.dromara.sis.domain.vo.SisAuthRecordVo;
|
||||||
@@ -34,6 +42,9 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
|||||||
|
|
||||||
private final SisAuthRecordMapper baseMapper;
|
private final SisAuthRecordMapper baseMapper;
|
||||||
|
|
||||||
|
private final ISisAccessControlService accessControlService;
|
||||||
|
private final ISisElevatorInfoService elevatorInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询授权记录
|
* 查询授权记录
|
||||||
*
|
*
|
||||||
@@ -88,27 +99,44 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean insertByBo(SisAuthRecordBo bo) {
|
public Boolean insertByBo(SisAuthRecordBo bo) {
|
||||||
boolean flag = false;
|
if (CollUtil.isEmpty(bo.getDeviceIds())) {
|
||||||
log.info("开始写入门禁授权记录,acIds:{}", bo.getAcIdList());
|
return false;
|
||||||
for (Long acId : bo.getAcIdList()) {
|
}
|
||||||
SisAuthRecord add = MapstructUtils.convert(bo, SisAuthRecord.class);
|
|
||||||
Assert.notNull(add, "数据处理失败");
|
|
||||||
|
|
||||||
add.setDeviceType(1);
|
// 每次授权先删除上一次授权信息
|
||||||
add.setDeviceId(acId);
|
deleteByLibId(bo.getLibId());
|
||||||
flag = baseMapper.insert(add) > 0;
|
|
||||||
|
// 过滤不是设备的节点数据
|
||||||
|
// 门禁设备
|
||||||
|
List<SisAccessControlVo> acVoList = accessControlService.queryListByIds(bo.getDeviceIds());
|
||||||
|
// 电梯设备
|
||||||
|
List<SisElevatorInfoVo> eleVoList = elevatorInfoService.queryListByIds(bo.getDeviceIds());
|
||||||
|
if (CollUtil.isEmpty(acVoList) || CollUtil.isEmpty(eleVoList)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量写入授权数据
|
||||||
|
boolean flag = false;
|
||||||
|
log.info("开始写入门禁授权记录,acIds:{}", acVoList);
|
||||||
|
for (SisAccessControlVo ac : acVoList) {
|
||||||
|
SisAuthRecord authRecord = new SisAuthRecord();
|
||||||
|
|
||||||
|
authRecord.setDeviceType(1);
|
||||||
|
authRecord.setDeviceId(ac.getId());
|
||||||
|
authRecord.setLibId(bo.getLibId());
|
||||||
|
flag = baseMapper.insert(authRecord) > 0;
|
||||||
Assert.isTrue(flag, "写入门禁授权记录失败!");
|
Assert.isTrue(flag, "写入门禁授权记录失败!");
|
||||||
}
|
}
|
||||||
log.info("写入门禁授权记录完成");
|
log.info("写入门禁授权记录完成");
|
||||||
|
|
||||||
log.info("开始写入电梯授权记录,eleIds:{}", bo.getEleIdList());
|
log.info("开始写入电梯授权记录,eleIds:{}", eleVoList);
|
||||||
for (Long ele : bo.getEleIdList()) {
|
for (SisElevatorInfoVo ele : eleVoList) {
|
||||||
SisAuthRecord add = MapstructUtils.convert(bo, SisAuthRecord.class);
|
SisAuthRecord authRecord = new SisAuthRecord();
|
||||||
Assert.notNull(add, "数据处理失败");
|
|
||||||
|
|
||||||
add.setDeviceType(2);
|
authRecord.setDeviceType(2);
|
||||||
add.setDeviceId(ele);
|
authRecord.setLibId(bo.getLibId());
|
||||||
flag = baseMapper.insert(add) > 0;
|
authRecord.setDeviceId(ele.getElevatorId());
|
||||||
|
flag = baseMapper.insert(authRecord) > 0;
|
||||||
Assert.isTrue(flag, "写入电梯授权记录失败!");
|
Assert.isTrue(flag, "写入电梯授权记录失败!");
|
||||||
}
|
}
|
||||||
log.info("写入电梯授权记录完成");
|
log.info("写入电梯授权记录完成");
|
||||||
@@ -150,4 +178,91 @@ public class SisAuthRecordServiceImpl implements ISisAuthRecordService {
|
|||||||
}
|
}
|
||||||
return baseMapper.deleteByIds(ids) > 0;
|
return baseMapper.deleteByIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询库id授权的设备
|
||||||
|
*
|
||||||
|
* @param libId 人像库id
|
||||||
|
* @return List<SisAuthRecord>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SisAuthRecord> queryAuthDevice(String libId) {
|
||||||
|
LambdaQueryWrapper<SisAuthRecord> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(SisAuthRecord::getLibId, libId);
|
||||||
|
return baseMapper.selectList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据人像库id删除授权记录
|
||||||
|
*
|
||||||
|
* @param libId 人像库id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Boolean deleteByLibId(Long libId){
|
||||||
|
LambdaQueryWrapper<SisAuthRecord> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.eq(SisAuthRecord::getLibId, libId);
|
||||||
|
return baseMapper.delete(lqw) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有可授权设备树
|
||||||
|
*
|
||||||
|
* @return List<TreeNode<Long>>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TreeNode<Long>> authDeviceTree(){
|
||||||
|
// 暂时将所有数据放入写死的根节点中
|
||||||
|
TreeNode<Long> root = new TreeNode<>();
|
||||||
|
root.setLevel(0);
|
||||||
|
root.setCode(0L);
|
||||||
|
root.setParentCode(-1L);
|
||||||
|
root.setLabel("授权设备");
|
||||||
|
|
||||||
|
// 创建门禁设备父节点
|
||||||
|
TreeNode<Long> accessNode = new TreeNode<>();
|
||||||
|
accessNode.setLevel(1);
|
||||||
|
accessNode.setCode(1L);
|
||||||
|
accessNode.setParentCode(0L);
|
||||||
|
accessNode.setLabel("门禁设备");
|
||||||
|
|
||||||
|
// 创建电梯父节点
|
||||||
|
TreeNode<Long> elevatorNode = new TreeNode<>();
|
||||||
|
elevatorNode.setLevel(1);
|
||||||
|
elevatorNode.setCode(2L);
|
||||||
|
elevatorNode.setParentCode(0L);
|
||||||
|
elevatorNode.setLabel("电梯设备");
|
||||||
|
|
||||||
|
|
||||||
|
List<SisAccessControlVo> acVoList = accessControlService.queryList(new SisAccessControlBo());
|
||||||
|
List<SisElevatorInfoVo> eleVoList = elevatorInfoService.queryList(new SisElevatorInfoBo());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<TreeNode<Long>> acChildrenList = acVoList.stream().map(item -> {
|
||||||
|
TreeNode<Long> node = new TreeNode<>();
|
||||||
|
node.setLevel(2);
|
||||||
|
node.setCode(item.getId());
|
||||||
|
node.setParentCode(1L);
|
||||||
|
node.setLabel(item.getAccessName());
|
||||||
|
return node;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
List<TreeNode<Long>> eleChildrenList = eleVoList.stream().map(item -> {
|
||||||
|
TreeNode<Long> node = new TreeNode<>();
|
||||||
|
node.setLevel(2);
|
||||||
|
node.setCode(item.getElevatorId());
|
||||||
|
node.setParentCode(2L);
|
||||||
|
node.setLabel(item.getElevatorName());
|
||||||
|
return node;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
// 将子节点列表分别添加到对应的父节点
|
||||||
|
accessNode.setChildren(acChildrenList);
|
||||||
|
elevatorNode.setChildren(eleChildrenList);
|
||||||
|
|
||||||
|
// 最后将两个父节点添加到根节点
|
||||||
|
root.setChildren(List.of(accessNode, elevatorNode));
|
||||||
|
return List.of(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -253,4 +253,15 @@ public class SisElevatorInfoServiceImpl implements ISisElevatorInfoService {
|
|||||||
public List<SisElevatorInfoVo> queryAll() {
|
public List<SisElevatorInfoVo> queryAll() {
|
||||||
return baseMapper.selectVoList();
|
return baseMapper.selectVoList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据查询列表
|
||||||
|
*
|
||||||
|
* @param ids 电梯id
|
||||||
|
* @return 列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SisElevatorInfoVo> queryListByIds(Collection<Long> ids){
|
||||||
|
return baseMapper.selectVoByIds(ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user