新增设备分组
This commit is contained in:
@ -1,105 +0,0 @@
|
||||
package com.fuyuanshen.equipment.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.*;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.log.annotation.Log;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.common.log.enums.BusinessType;
|
||||
import com.fuyuanshen.common.excel.utils.ExcelUtil;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
|
||||
import com.fuyuanshen.equipment.service.IDeviceGroupService;
|
||||
|
||||
/**
|
||||
* 设备分组
|
||||
*
|
||||
* @author Lion Li
|
||||
* @date 2025-08-08
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/fys-equipment/group")
|
||||
public class DeviceGroupController extends BaseController {
|
||||
|
||||
private final IDeviceGroupService deviceGroupService;
|
||||
|
||||
/**
|
||||
* 查询设备分组列表
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:list")
|
||||
@GetMapping("/list")
|
||||
public R<List<DeviceGroupVo>> list(DeviceGroupBo bo) {
|
||||
List<DeviceGroupVo> list = deviceGroupService.queryList(bo);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备分组列表
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:export")
|
||||
@Log(title = "设备分组", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(DeviceGroupBo bo, HttpServletResponse response) {
|
||||
List<DeviceGroupVo> list = deviceGroupService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "设备分组", DeviceGroupVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备分组详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:query")
|
||||
@GetMapping("/{id}")
|
||||
public R<DeviceGroupVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(deviceGroupService.queryById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备分组
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:add")
|
||||
@Log(title = "设备分组", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceGroupBo bo) {
|
||||
return toAjax(deviceGroupService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备分组
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:edit")
|
||||
@Log(title = "设备分组", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceGroupBo bo) {
|
||||
return toAjax(deviceGroupService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备分组
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@SaCheckPermission("fys-equipment:group:remove")
|
||||
@Log(title = "设备分组", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(deviceGroupService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.equipment.domain.DeviceGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
@ -21,7 +23,7 @@ public class DeviceGroupBo extends BaseEntity {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@NotNull(message = "主键ID不能为空", groups = { EditGroup.class })
|
||||
// @NotNull(message = "主键ID不能为空", groups = { EditGroup.class })
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@ -33,7 +35,7 @@ public class DeviceGroupBo extends BaseEntity {
|
||||
/**
|
||||
* 状态:0-禁用,1-正常
|
||||
*/
|
||||
@NotNull(message = "状态:0-禁用,1-正常不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
// @NotNull(message = "状态:0-禁用,1-正常不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
@ -49,7 +51,7 @@ public class DeviceGroupBo extends BaseEntity {
|
||||
/**
|
||||
* 删除标记:0-未删除,1-已删除
|
||||
*/
|
||||
@NotNull(message = "删除标记:0-未删除,1-已删除不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
// @NotNull(message = "删除标记:0-未删除,1-已删除不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private Long isDeleted;
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.fuyuanshen.equipment.domain.bo;
|
||||
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.equipment.domain.DeviceRepairRecords;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
@ -11,7 +11,7 @@ import lombok.Data;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -64,5 +64,9 @@ public class DeviceGroupVo implements Serializable {
|
||||
@ExcelProperty(value = "删除标记:0-未删除,1-已删除")
|
||||
private Long isDeleted;
|
||||
|
||||
/**
|
||||
* 嵌套子分组
|
||||
*/
|
||||
private List<DeviceGroupVo> children;
|
||||
|
||||
}
|
||||
|
@ -66,4 +66,5 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
||||
* @return
|
||||
*/
|
||||
List<Device> findByOriginalDeviceId(Long originalDeviceId);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@ -37,7 +39,7 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
* @return 设备分组
|
||||
*/
|
||||
@Override
|
||||
public DeviceGroupVo queryById(Long id){
|
||||
public DeviceGroupVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
@ -66,6 +68,7 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
return lqw;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备分组
|
||||
*
|
||||
@ -74,8 +77,21 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(DeviceGroupBo bo) {
|
||||
|
||||
// 验证分组名称唯一性
|
||||
DeviceGroup deviceGroup = baseMapper.selectOne(new QueryWrapper<DeviceGroup>().eq("group_name", bo.getGroupName()));
|
||||
if (deviceGroup != null) {
|
||||
throw new RuntimeException("分组名称已存在,请勿重复添加");
|
||||
}
|
||||
|
||||
// 验证父分组是否存在(如果提供了parentId)
|
||||
DeviceGroup pDeviceGroup = baseMapper.selectById(bo.getParentId());
|
||||
if (bo.getParentId() != null && pDeviceGroup == null) {
|
||||
throw new RuntimeException("父分组不存在");
|
||||
}
|
||||
|
||||
DeviceGroup add = MapstructUtils.convert(bo, DeviceGroup.class);
|
||||
validEntityBeforeSave(add);
|
||||
// validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
@ -83,6 +99,7 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备分组
|
||||
*
|
||||
@ -99,8 +116,8 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(DeviceGroup entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
private void validEntityBeforeSave(DeviceGroup entity) {
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,8 +129,8 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
if (isValid) {
|
||||
// TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceRepairRecordsBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo;
|
||||
|
Reference in New Issue
Block a user