package com.cutebytec.base.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cutebytec.base.api.entity.BaseCustomerDeviceEntity;
import com.cutebytec.base.api.entity.BaseDeviceEntity;
import com.cutebytec.base.api.vo.BaseCustomerDeviceVo;
import com.cutebytec.base.constant.DeviceManageTypeConstant;
import com.cutebytec.base.service.BaseCustomerDeviceService;
import com.cutebytec.cutebyte.common.core.util.R;
import com.cutebytec.cutebyte.common.log.annotation.SysLog;
import com.cutebytec.base.service.BaseDeviceService;
import com.cutebytec.cutebyte.common.security.util.SecurityUtils;
import com.cutebytec.ys.api.feign.RemoteYsAccountService;
import com.cutebytec.ys.api.feign.RemoteYsDeviceService;
import com.cutebytec.ys.api.properties.YsProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* 设备管理
*
* @author lty
* @date 2024-03-11 08:25:21
*/
@RestController
@RequiredArgsConstructor //这一个保证了构造函数注入 所以可以不用 变量注入
@RequestMapping("/baseDevice" )
@Tag(description = "baseDevice" , name = "设备管理管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BaseDeviceController {
private final BaseDeviceService baseDeviceService;
private final YsProperty ysProperty;
private final RemoteYsAccountService remoteYsAccountService;
private final RemoteYsDeviceService remoteYsDeviceService;
private final BaseCustomerDeviceService baseCustomerDeviceService;
/**
* 分页查询客户具备权限的所有设备不包括
* @param page 分页对象
* @return
*/
@Operation(summary = "分页查询客户设备" , description = "分页查询客户设备" )
@GetMapping("/customer/allDev/page" )
public R getJustDeviceCustomerPage(@ParameterObject Page page) {
//条件查询系统中所有设备
//todo 应该先查出设备所有具备权限的ID列表,再去查询过来
LambdaQueryWrapper<BaseDeviceEntity> dwrapper = Wrappers.lambdaQuery();
dwrapper.eq(BaseDeviceEntity::getType, DeviceManageTypeConstant.DEVICE);
IPage res=baseDeviceService.page(page,dwrapper);
return R.ok(res);
}
/**
* 分页查询客户设备 只可以查询出分配给了 该客户都得设备
* @param page 分页对象
* @param baseDevice 设备管理
* @return
*/
@Operation(summary = "分页查询客户设备" , description = "分页查询客户设备" )
@GetMapping("/customer/page" )
public R getDeviceCustomerPage(@ParameterObject Page page, @ParameterObject BaseDeviceEntity baseDevice) {
System.out.println("ggggg");
IPage res=null;
Long id = SecurityUtils.getUser().getId();
if(Objects.isNull(id)){
throw new RuntimeException("身份认证失败");
}
//查询条件查询用户具备管理权限得devId
LambdaQueryWrapper<BaseCustomerDeviceEntity> wrapper = Wrappers.lambdaQuery();
wrapper.select(BaseCustomerDeviceEntity::getDeviceId);
wrapper.eq(BaseCustomerDeviceEntity::getCustomerId,id);
//条件查询设备
LambdaQueryWrapper<BaseDeviceEntity> dwrapper = Wrappers.lambdaQuery();
dwrapper.eq(StrUtil.isNotBlank(baseDevice.getDeviceSerial()),BaseDeviceEntity::getDeviceSerial,baseDevice.getDeviceSerial());
dwrapper.like(StrUtil.isNotBlank(baseDevice.getName()),BaseDeviceEntity::getName,baseDevice.getName());
dwrapper.eq(Objects.nonNull(baseDevice.getParentId()),BaseDeviceEntity::getParentId,baseDevice.getParentId());
dwrapper.eq(StrUtil.isNotBlank(baseDevice.getYsStatus()),BaseDeviceEntity::getYsStatus,baseDevice.getYsStatus());
dwrapper.eq(StrUtil.isNotBlank(baseDevice.getType()),BaseDeviceEntity::getType,baseDevice.getType());
//todo 如果前端传入了parentId则要判断当前用户是否具备parentId得这个权限
// (因为这个时候是用户在前台点击了一个用户具备权限得设备文件夹然后查看文件夹里面得设备,不过前提先判断权限)
// (从数据库查询出所有得pId递归到最上级得pid作为列表)
// 然后看是否可以从数据库设备权限表中查找树上面对应id得设备即可 能找多说明具备权限 不能找到说明不具备
Long parentId = baseDevice.getParentId();
if(Objects.nonNull(parentId)){
Set<Long> idByIdUpRecursive = baseDeviceService.getIdByIdUpRecursive(parentId);
if(Objects.isNull(idByIdUpRecursive) || idByIdUpRecursive.size()<=0){
throw new RuntimeException("设备不存在未知异常!");
}
wrapper.in(BaseCustomerDeviceEntity::getDeviceId,idByIdUpRecursive);
//判断用户是否具备当前访问设备目录的数据权限
List<BaseCustomerDeviceEntity> list = baseCustomerDeviceService.list(wrapper);
if(Objects.isNull(list) || list.size()<=0){
throw new RuntimeException("不具备访问权限");
}
res=baseDeviceService.page(page,dwrapper);
}else{
wrapper.eq(BaseCustomerDeviceEntity::getCustomerId,id);
// List<Long> devIdList = baseCustomerDeviceService.listObjs(page,wrapper);
//分页写在下面最后baseDeviceService.page 也可以 不再这里分页也可以 都可以这里暂时用这种 (区别和上一个分页的地方不同0
IPage iPage = baseCustomerDeviceService.selfPageGetDevId(page, wrapper);
List<Long> devIdList = iPage.getRecords();
//devIdLis为空应该直接返回空(改用还没有任何具备权限的设备)
if(Objects.isNull(devIdList) || devIdList.size()<=0){
return R.ok(new Page<>());
}
//其它情况查询得就是用户的根目录下具备权限的所有设备
dwrapper.in(BaseDeviceEntity::getId, devIdList);
iPage.setRecords(baseDeviceService.list(dwrapper));
res=iPage;
}
return R.ok(res);
}
/**
* (缺少堆该用户是否具备该设备的访问权限再次去获取)
* @param baseDevice
* @return
*/
@Operation(summary = "获取设备访问token" , description = "获取设备访问token" )
@PostMapping("/device/token" )
public R getDeviceCustomerPage(@RequestBody BaseDeviceEntity baseDevice) {
return R.ok(baseDeviceService.getDeviceAccessToken(baseDevice));
}
//todo 或许为了统一之后其实或许(这里可以用设备serial代替id来查询单个设备信息或者其它操作等)
/**
* 通过id查询设备信息
* @return R
*/
@Operation(summary = "customer查询设备信息" , description = "通过id查询" )
@PostMapping("/getDevInfo" )
public R getDevInfo(@RequestBody BaseDeviceEntity baseDevice) {
LambdaQueryWrapper<BaseDeviceEntity> dwrapper = Wrappers.lambdaQuery();
// dwrapper.eq(Objects.nonNull(baseDevice.getDeviceSerial()),BaseDeviceEntity::getDeviceSerial,baseDevice.getDeviceSerial());
if(Objects.isNull(baseDevice.getId()) && Objects.isNull(baseDevice.getDeviceSerial())){
throw new RuntimeException("设备id或者序列号不可以为空");
}
dwrapper.eq(BaseDeviceEntity::getId,baseDevice.getId());
dwrapper.or();
dwrapper.eq(Objects.nonNull(baseDevice.getDeviceSerial()),BaseDeviceEntity::getDeviceSerial,baseDevice.getDeviceSerial());
BaseDeviceEntity one = baseDeviceService.getOne(dwrapper);
return R.ok(one);
}
/********************* 下面是sys管理端用的居多 上面则
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
cutebyte-end是一个基于Java开发的室内异常行为监测报警系统,包含751个文件,其中包括486个Java源文件、71个JavaScript文件、55个XML文件、17个YAML文件、16个Imports文件、11个TTF字体文件、11个WOFF文件、10个CSS文件、9个WOFF2文件和8个SQL文件。该项目为用户提供了一个全面、高效的室内异常行为监测报警解决方案,支持多平台浏览,具备良好的用户体验和实用性。
资源推荐
资源详情
资源评论
![epub](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GZ.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GZ.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GZ.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GZ.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GZ.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 750 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/326bc6aa99bd4e068708ab91a88ba159_weixin_44087733.jpg!1)
沐知全栈开发
- 粉丝: 5216
- 资源: 5025
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)