新增设备处理相关方法

This commit is contained in:
lxd 2025-06-10 14:51:49 +08:00
parent 0b378f2f21
commit 15fc9d5311
9 changed files with 35 additions and 9 deletions

View File

@ -58,7 +58,12 @@ public class DeviceController {
deviceService.deleteDevice(id); deviceService.deleteDevice(id);
return success(true); return success(true);
} }
@DeleteMapping("/deletecode")
@Operation(summary = "根据设备ID删除设备")
public CommonResult<Boolean> deleteDeviceId(@RequestParam("devicecode") Integer devicecode) {
deviceService.deleteDeviceId(devicecode);
return success(true);
}
@GetMapping("/get") @GetMapping("/get")
@Operation(summary = "获得设备") @Operation(summary = "获得设备")
@Parameter(name = "id", description = "编号", required = true, example = "1024") @Parameter(name = "id", description = "编号", required = true, example = "1024")

View File

@ -19,7 +19,6 @@ public class DeviceSaveReqVO {
private String devicename; private String devicename;
@Schema(description = "设备ID/编号", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "设备ID/编号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "设备ID/编号不能为空")
private Integer devicecode; private Integer devicecode;
@Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")

View File

@ -58,7 +58,11 @@ public class DeviceuserController {
deviceuserService.deleteDeviceuser(id); deviceuserService.deleteDeviceuser(id);
return success(true); return success(true);
} }
@GetMapping("/getDevCount")
@Operation(summary = "获得关联设备人员数量")
public CommonResult<Integer> getDeviceusercount(@RequestParam("devicecode") Integer devicecode) {
return success(deviceuserService.getDeviceusercount(devicecode));
}
@GetMapping("/get") @GetMapping("/get")
@Operation(summary = "获得设备人员关联") @Operation(summary = "获得设备人员关联")
@Parameter(name = "id", description = "编号", required = true, example = "1024") @Parameter(name = "id", description = "编号", required = true, example = "1024")

View File

@ -15,12 +15,11 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@TableName("tb_deviceuser") @TableName("tb_deviceuser")
@KeySequence("tb_deviceuser_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写 @KeySequence("tb_deviceuser_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data @Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class DeviceuserDO extends BaseDO { public class DeviceuserDO {
/** /**
* 主键ID * 主键ID

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.deviceuser.DeviceuserDO; import cn.iocoder.yudao.module.system.dal.dataobject.deviceuser.DeviceuserDO;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.deviceuser.vo.*; import cn.iocoder.yudao.module.system.controller.admin.deviceuser.vo.*;
@ -15,6 +16,7 @@ import cn.iocoder.yudao.module.system.controller.admin.deviceuser.vo.*;
* @author 全智安 * @author 全智安
*/ */
@Mapper @Mapper
@InterceptorIgnore(tenantLine = "true")
public interface DeviceuserMapper extends BaseMapperX<DeviceuserDO> { public interface DeviceuserMapper extends BaseMapperX<DeviceuserDO> {
default PageResult<DeviceuserDO> selectPage(DeviceuserPageReqVO reqVO) { default PageResult<DeviceuserDO> selectPage(DeviceuserPageReqVO reqVO) {

View File

@ -35,6 +35,10 @@ public interface DeviceService {
* @param id 编号 * @param id 编号
*/ */
void deleteDevice(Integer id); void deleteDevice(Integer id);
/*
* 根据设备ID 删除数据
* */
void deleteDeviceId(Integer devicecode);
/** /**
* 获得设备 * 获得设备

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.service.device; package cn.iocoder.yudao.module.system.service.device;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -51,7 +52,15 @@ public class DeviceServiceImpl implements DeviceService {
// 删除 // 删除
deviceMapper.deleteById(id); deviceMapper.deleteById(id);
} }
@Override
public void deleteDeviceId(Integer devicecode)
{
// 创建 QueryWrapper 实例并指定删除条件
QueryWrapper<DeviceDO> wrapper = new QueryWrapper<>();
wrapper.eq("devicecode", devicecode); // device_name 字段删除
deviceMapper.delete(wrapper);
}
private void validateDeviceExists(Integer id) { private void validateDeviceExists(Integer id) {
if (deviceMapper.selectById(id) == null) { if (deviceMapper.selectById(id) == null) {
throw exception(DEVICE_NOT_EXISTS); throw exception(DEVICE_NOT_EXISTS);

View File

@ -43,6 +43,10 @@ public interface DeviceuserService {
* @return 设备人员关联 * @return 设备人员关联
*/ */
DeviceuserDO getDeviceuser(Integer id); DeviceuserDO getDeviceuser(Integer id);
/*
* 设备ID 查询设备人员数量
* */
Integer getDeviceusercount(Integer devicecode);
/** /**
* 获得设备人员关联分页 * 获得设备人员关联分页

View File

@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.system.service.deviceuser;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.deviceuser.vo.*; import cn.iocoder.yudao.module.system.controller.admin.deviceuser.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.deviceuser.DeviceuserDO; import cn.iocoder.yudao.module.system.dal.dataobject.deviceuser.DeviceuserDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.dal.mysql.deviceuser.DeviceuserMapper; import cn.iocoder.yudao.module.system.dal.mysql.deviceuser.DeviceuserMapper;
@ -65,7 +62,10 @@ public class DeviceuserServiceImpl implements DeviceuserService {
public DeviceuserDO getDeviceuser(Integer id) { public DeviceuserDO getDeviceuser(Integer id) {
return deviceuserMapper.selectById(id); return deviceuserMapper.selectById(id);
} }
@Override
public Integer getDeviceusercount(Integer devicecode) {
return deviceuserMapper.selectCount(DeviceuserDO::getDeviceid, devicecode).intValue();
}
@Override @Override
public PageResult<DeviceuserDO> getDeviceuserPage(DeviceuserPageReqVO pageReqVO) { public PageResult<DeviceuserDO> getDeviceuserPage(DeviceuserPageReqVO pageReqVO) {
return deviceuserMapper.selectPage(pageReqVO); return deviceuserMapper.selectPage(pageReqVO);