package com.by4cloud.platformx.device.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.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.by4cloud.platformx.common.core.util.R;
|
import com.by4cloud.platformx.common.log.annotation.SysLog;
|
import com.by4cloud.platformx.device.constant.MaxSizeContant;
|
import com.by4cloud.platformx.device.entity.DeviceClass;
|
import com.by4cloud.platformx.device.entity.DeviceInventory;
|
import com.by4cloud.platformx.device.entity.MaxSize;
|
import com.by4cloud.platformx.device.service.DeviceClassService;
|
import com.by4cloud.platformx.device.service.JcMaxSizeService;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
import org.springdoc.api.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 javax.validation.constraints.Max;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 设备分类表
|
*
|
* @author pig
|
* @date 2025-03-05 10:46:29
|
*/
|
@RestController
|
@RequiredArgsConstructor
|
@RequestMapping("/deviceClass" )
|
@Tag(description = "deviceClass" , name = "设备分类表管理" )
|
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
public class DeviceClassController {
|
|
private final DeviceClassService deviceClassService;
|
private final JcMaxSizeService maxSizeService;
|
|
/**
|
* 分页查询
|
* @param page 分页对象
|
* @param deviceClass 设备分类表
|
* @return
|
*/
|
@Operation(summary = "分页查询" , description = "分页查询" )
|
@GetMapping("/page" )
|
@PreAuthorize("@pms.hasPermission('platformx_deviceClass_view')" )
|
public R getDeviceClassPage(@ParameterObject Page page, @ParameterObject DeviceClass deviceClass) {
|
LambdaQueryWrapper<DeviceClass> wrapper = Wrappers.lambdaQuery();
|
wrapper.like(StrUtil.isNotBlank(deviceClass.getName()),DeviceClass::getName,deviceClass.getName());
|
wrapper.eq(StrUtil.isNotBlank(deviceClass.getNumber()),DeviceClass::getNumber,deviceClass.getNumber());
|
return R.ok(deviceClassService.page(page, wrapper));
|
}
|
|
// /**
|
// * 返回树形菜单集合
|
// * @return 树形菜单
|
// */
|
// @GetMapping(value = "/tree")
|
// public R getTree(String name, Long parentId) {
|
// return R.ok(deviceClassService.selectTree(name,parentId));
|
// }
|
|
/**
|
* 返回树形菜单集合
|
* @return 树形菜单
|
*/
|
@GetMapping(value = "/tree")
|
public R getTree() {
|
return R.ok(deviceClassService.selectTree());
|
}
|
|
|
|
/**
|
* 通过id查询设备分类表
|
* @param id id
|
* @return R
|
*/
|
@Operation(summary = "通过id查询" , description = "通过id查询" )
|
@GetMapping("/{id}" )
|
public R getById(@PathVariable("id" ) Long id) {
|
DeviceClass byId = deviceClassService.getById(id);
|
byId.setParentId(byId.getPId().intValue());
|
return R.ok(byId);
|
}
|
|
/**
|
* 新增设备分类表
|
* @param deviceClass 设备分类表
|
* @return R
|
*/
|
@Operation(summary = "新增设备分类表" , description = "新增设备分类表" )
|
@SysLog("新增设备分类表" )
|
@PostMapping
|
public R save(@RequestBody DeviceClass deviceClass) {
|
if(deviceClass.getParentId()==null){
|
return R.failed("上级分类未选择!");
|
}
|
deviceClass.setNumber(maxSizeService.nextNo(MaxSizeContant.DEVICE_CLASS_NUM));
|
deviceClass.setPId(deviceClass.getParentId().longValue());
|
return R.ok(deviceClassService.save(deviceClass));
|
}
|
|
/**
|
* 修改设备分类表
|
* @param deviceClass 设备分类表
|
* @return R
|
*/
|
@Operation(summary = "修改设备分类表" , description = "修改设备分类表" )
|
@SysLog("修改设备分类表" )
|
@PutMapping
|
@PreAuthorize("@pms.hasPermission('platformx_deviceClass_edit')" )
|
public R updateById(@RequestBody DeviceClass deviceClass) {
|
if(deviceClass.getParentId()==null){
|
return R.failed("上级分类未选择!");
|
}
|
deviceClass.setPId(deviceClass.getParentId().longValue());
|
return R.ok(deviceClassService.updateById(deviceClass));
|
}
|
|
/**
|
* 通过id删除设备分类表
|
* @param ids id列表
|
* @return R
|
*/
|
@Operation(summary = "通过id删除设备分类表" , description = "通过id删除设备分类表" )
|
@SysLog("通过id删除设备分类表" )
|
@DeleteMapping
|
@PreAuthorize("@pms.hasPermission('platformx_deviceClass_del')" )
|
public R removeById(@RequestBody Long[] ids) {
|
return R.ok(deviceClassService.removeBatchByIds(CollUtil.toList(ids)));
|
}
|
|
|
/**
|
* 导出excel 表格
|
* @param deviceClass 查询条件
|
* @param ids 导出指定ID
|
* @return excel 文件流
|
*/
|
@ResponseExcel
|
@GetMapping("/export")
|
@PreAuthorize("@pms.hasPermission('platformx_deviceClass_export')" )
|
public List<DeviceClass> export(DeviceClass deviceClass,Long[] ids) {
|
return deviceClassService.list(Wrappers.lambdaQuery(deviceClass).in(ArrayUtil.isNotEmpty(ids), DeviceClass::getId, ids));
|
}
|
}
|