Compare commits
2 Commits
74cefe9cc3
...
f9d9dadf08
Author | SHA1 | Date | |
---|---|---|---|
f9d9dadf08 | |||
e4df695f5e |
@ -114,4 +114,21 @@ public class DeviceGroupController extends BaseController {
|
||||
return toAjax(deviceGroupService.deleteWithValidByIds(List.of(ids), true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定设备分组
|
||||
*
|
||||
* @param groupId 分组id
|
||||
* @param deviceId 设备id
|
||||
*/
|
||||
@Operation(summary = "绑定设备分组")
|
||||
// @SaCheckPermission("fys-equipment:group:remove")
|
||||
@Log(title = "绑定设备分组", businessType = BusinessType.DELETE)
|
||||
@GetMapping("/groupId/{deviceId}")
|
||||
public R<Void> bindingDevice(@NotEmpty(message = "分组id 不能为空") @PathVariable Long groupId,
|
||||
@NotEmpty(message = "设备id 不能为空") @PathVariable Long[] deviceId) {
|
||||
return toAjax(deviceGroupService.bindingDevice(groupId, deviceId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.fuyuanshen.equipment.service;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -56,4 +57,14 @@ public interface IDeviceGroupService {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
|
||||
/**
|
||||
* 绑定设备分组
|
||||
*
|
||||
* @param groupId 分组id
|
||||
* @param deviceId 设备id
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
Boolean bindingDevice(@NotEmpty(message = "分组id 不能为空") Long groupId, @NotEmpty(message = "设备id 不能为空") Long[] deviceId);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
@ -11,6 +12,8 @@ import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -22,6 +25,7 @@ import com.fuyuanshen.equipment.mapper.DeviceGroupMapper;
|
||||
import com.fuyuanshen.equipment.service.IDeviceGroupService;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
@ -39,6 +43,7 @@ import java.util.stream.Collectors;
|
||||
public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
|
||||
private final DeviceGroupMapper baseMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
|
||||
|
||||
/**
|
||||
@ -63,7 +68,7 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
public List<DeviceGroupVo> queryList(DeviceGroupBo bo) {
|
||||
Page<Device> page = new Page<>(bo.getPageNum(), bo.getPageSize());
|
||||
// 1. 查询顶级分组(parent_id为null)
|
||||
IPage<DeviceGroup> rootGroups = baseMapper.selectRootGroups(bo, page);
|
||||
IPage<DeviceGroup> rootGroups = baseMapper.selectRootGroups(bo, page);
|
||||
List<DeviceGroup> records = rootGroups.getRecords();
|
||||
|
||||
// 2. 递归构建树形结构
|
||||
@ -169,4 +174,27 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定设备分组
|
||||
*
|
||||
* @param groupId 分组id
|
||||
* @param deviceId 设备id
|
||||
* @return 是否绑定成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean bindingDevice(Long groupId, Long[] deviceId) {
|
||||
|
||||
if (deviceId != null && deviceId.length > 0) {
|
||||
// 创建更新条件
|
||||
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.in("id", Arrays.asList(deviceId));
|
||||
updateWrapper.set("group_id", groupId);
|
||||
|
||||
// 执行批量更新
|
||||
deviceMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user