设备类型管理接口

This commit is contained in:
2025-07-01 09:32:22 +08:00
parent 933e74235f
commit 440aec266b
5 changed files with 28 additions and 111 deletions

View File

@ -1,6 +1,5 @@
package com.fuyuanshen.common.encrypt.utils;
import com.fuyuanshen.common.core.domain.model.LoginBody;
import com.fuyuanshen.common.core.domain.model.PasswordLoginBody;
/**
@ -40,8 +39,8 @@ public class EncryptUtilsTest {
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
loginBody.setGrantType("password");
loginBody.setTenantId("894078");
loginBody.setCode("2");
loginBody.setUuid("3ccffe0db9a7458cb732f95736019c6f");
loginBody.setCode("21");
loginBody.setUuid("39785885a3ef42d59501502848cd1dcb");
// loginBody.setUsername("admin");
// loginBody.setPassword("admin123");
loginBody.setUsername("dyf");

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fuyuanshen.common.tenant.core.TenantEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@ -19,36 +20,29 @@ import lombok.Data;
public class DeviceType extends TenantEntity {
@TableId(value = "id", type = IdType.AUTO)
// @Schema(value = "ID", hidden = true)
@Schema(name = "ID", hidden = true)
private Long id;
// @Schema(value = "客户号")
@Schema(name = "客户号")
private Long customerId;
// @Schema(value = "创建该类型的客户")
@Schema(name = "创建该类型的客户")
private Long ownerCustomerId;
/**
* 租户ID
*/
// @TableField(value = "tenant_id")
// @Schema(hidden = true)
// private Long tenantId;
@NotBlank(message = "设备类型名称不能为空")
// @Schema(value = "类型名称", required = true)
@Schema(name = "类型名称", required = true)
private String typeName;
// @Schema(value = "是否支持蓝牙")
@Schema(name = "是否支持蓝牙")
private Boolean isSupportBle;
// @Schema(value = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
@Schema(name = "定位方式", example = "0:无;1:GPS;2:基站;3:wifi;4:北斗")
private String locateMode;
// @Schema(value = "联网方式", example = "0:无;1:4G;2:WIFI")
@Schema(name = "联网方式", example = "0:无;1:4G;2:WIFI")
private String networkWay;
// @Schema(value = "通讯方式", example = "0:4G;1:蓝牙")
@Schema(name = "通讯方式", example = "0:4G;1:蓝牙")
private String communicationMode;

View File

@ -32,7 +32,6 @@ public interface DeviceTypeService extends IService<DeviceType> {
*/
List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria);
/**
* 查询所有设备类型
*
@ -48,7 +47,7 @@ public interface DeviceTypeService extends IService<DeviceType> {
void create(DeviceType resources);
/**
* 编辑
* 修改设备类型
*
* @param resources /
*/

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.common.core.utils.PageUtil;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
@ -37,11 +38,16 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
*/
@Override
public PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page) {
return PageUtil.toPage(deviceTypeMapper.findAll(criteria, page));
}
@Override
public List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria) {
return deviceTypeMapper.findAll(criteria);
}
/**
* 查询所有设备类型
*
@ -49,32 +55,9 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
*/
@Override
public List<DeviceType> queryDeviceTypes() {
// // JwtUserDto userCache = userCacheManager.getUserCache(SecurityUtils.getCurrentUsername());
// User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
// DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
// // 非超级管理员增加数据隔离(根据租户隔离)
// // if (userCache.getUser().getTenantId() != null && !userCache.getUser().getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
// // List<User> users = userMapper.findByTenantId(userCache.getUser().getTenantId());
// // Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
// // criteria.setCustomerIds(userIds);
// // }
//
// // 非超级管理员增加数据隔离(只能看到自己创建的设备类型)
// if (currentUser.getTenantId() != null && !currentUser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
// //
// QueryWrapper<User> wrapper = new QueryWrapper<>();
// wrapper.eq("username", SecurityUtils.getCurrentUsername());
// User user = userMapper.selectOne(wrapper);
// criteria.setCustomerId(user.getId());
// }
//
// return deviceTypeMapper.findAll(criteria);
return null;
}
@Override
public List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria) {
DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
Long userId = LoginHelper.getUserId();
criteria.setCustomerId(userId);
return deviceTypeMapper.findAll(criteria);
}
@ -87,19 +70,10 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DeviceType resources) {
// Long deviceTypeId = NanoId.generate(NanoIdLengthEnum.HIGH_CONCURRENCY.getLength());
// resources.setId(deviceTypeId);
// resources.setCustomerId(SecurityUtils.getCurrentUserId());
// resources.setOwnerCustomerId(SecurityUtils.getCurrentUserId());
// deviceTypeMapper.insert(resources);
//
// // 自动授权给自己
// DeviceTypeGrants deviceTypeGrants = new DeviceTypeGrants();
// deviceTypeGrants.setDeviceTypeId(deviceTypeId);
// deviceTypeGrants.setCustomerId(SecurityUtils.getCurrentUserId());
// deviceTypeGrants.setGrantorCustomerId(SecurityUtils.getCurrentUserId());
// deviceTypeGrants.setGrantedAt(new Date());
// deviceTypeGrantsMapper.insert(deviceTypeGrants);
Long userId = LoginHelper.getUserId();
resources.setCustomerId(userId);
resources.setOwnerCustomerId(userId);
deviceTypeMapper.insert(resources);
}
@ -111,17 +85,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DeviceType resources) {
//
// List<Device> deviceList = deviceMapper.selectList(new QueryWrapper<Device>().eq("device_type", resources.getId()));
// if (CollectionUtil.isNotEmpty(deviceList)) {
// throw new BadRequestException("该设备类型下已有设备,请先解绑设备!!!");
// }
//
// DeviceType deviceType = getById(resources.getId());
// deviceType.copy(resources);
// Timestamp timestamp = new Timestamp(System.currentTimeMillis());
// deviceType.setUpdateTime(timestamp);
// deviceTypeMapper.updateById(deviceType);
deviceTypeMapper.updateById(resources);
}
@ -133,24 +97,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(List<Long> ids) {
// // 查询所有与 device 关联的 deviceType IDs
// List<Device> deviceList = deviceMapper.selectList(new QueryWrapper<Device>().in("device_type", ids));
// // 提取与 device 关联的 deviceType IDs
// List<Long> filteredIds = deviceList.stream()
// .map(Device::getDeviceType)
// .distinct()
// .collect(Collectors.toList());
// // 从原始 ids 中移除已关联 device 的 id即过滤掉能查到结果的 id
// List<Long> idsToBeDeleted = ids.stream()
// .filter(id -> !filteredIds.contains(id))
// .collect(Collectors.toList());
// if (idsToBeDeleted.isEmpty()) {
// throw new BadRequestException("选中设备类型已绑定设备,请先解绑设备!!!");
// }
// // 删除过滤后的 id 列表
// deviceTypeMapper.deleteBatchIds(idsToBeDeleted);
// deviceTypeGrantsMapper.delete(new QueryWrapper<DeviceTypeGrants>().in("device_type_id", idsToBeDeleted));
deviceTypeMapper.deleteByIds(ids);
}

View File

@ -20,28 +20,6 @@
</sql>
<!-- 分页查询设备类型 -->
<select id="findAll1" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from device_type
<where>
<if test="criteria.typeName != null and criteria.typeName.trim() != ''">
and type_name like concat('%', TRIM(#{criteria.typeName}), '%')
</if>
<if test="criteria.customerId != null and !criteria.customerId.isEmpty()">
and customer_id IN
<foreach item="item" collection="criteria.customerId" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="criteria.tenantId != null">
and tenant_id = #{criteria.tenantId}
</if>
</where>
order by id desc
</select>
<!-- 查询所有设备类型 -->
<select id="findAll" resultMap="BaseResultMap">
SELECT DISTINCT dt.*