设备类型管理

This commit is contained in:
2025-06-30 18:03:43 +08:00
parent eac1b2e016
commit 933e74235f
8 changed files with 444 additions and 50 deletions

View File

@ -40,8 +40,8 @@ public class EncryptUtilsTest {
loginBody.setClientId("e5cd7e4891bf95d1d19206ce24a7b32e");
loginBody.setGrantType("password");
loginBody.setTenantId("894078");
loginBody.setCode("9");
loginBody.setUuid("54b415e4c4574e029aa522b5070538b0");
loginBody.setCode("2");
loginBody.setUuid("3ccffe0db9a7458cb732f95736019c6f");
// loginBody.setUsername("admin");
// loginBody.setPassword("admin123");
loginBody.setUsername("dyf");

View File

@ -0,0 +1,84 @@
package com.fuyuanshen.equipment.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import com.fuyuanshen.equipment.service.DeviceTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Description:
* @Author: WY
* @Date: 2025/5/13
**/
@Tag(name = "设备类型管理", description = "设备类型管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/deviceType")
public class DeviceTypeController {
private final DeviceTypeService deviceTypeService;
@GetMapping
@Operation(summary = "分页查询设备类型")
public ResponseVO<PageResult<DeviceType>> queryDeviceType(DeviceTypeQueryCriteria criteria) {
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
return ResponseVO.success(deviceTypeService.queryAll(criteria, page));
}
@GetMapping(value = "/all")
@Operation(summary = "查询所有设备类型")
public ResponseVO<Object> queryDeviceTypes() {
List<DeviceType> deviceTypes = deviceTypeService.queryDeviceTypes();
return ResponseVO.success(deviceTypes);
}
// @Log("新增设备类型")
@Operation(summary = "新增设备类型")
@PostMapping(value = "/add")
public ResponseVO<Object> createDeviceType(@Validated @RequestBody DeviceType resources) {
deviceTypeService.create(resources);
return ResponseVO.success(null);
}
// @Log("修改设备类型")
@Operation(summary = "修改设备类型")
@PutMapping(value = "/update")
public ResponseVO<Object> updateDeviceType(@Validated @RequestBody DeviceType resources) {
deviceTypeService.update(resources);
return ResponseVO.success(null);
}
// @Log("删除设备类型")
@Operation(summary = "删除设备类型")
@DeleteMapping(value = "/delete")
public ResponseEntity<Object> deleteDeviceType(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
deviceTypeService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping(value = "/communicationMode")
@Operation(summary = "获取设备类型通讯方式")
public ResponseVO<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
return ResponseVO.success(deviceTypeService.getById(id));
}
}

View File

@ -0,0 +1,36 @@
package com.fuyuanshen.equipment.domain.query;
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.Set;
/**
* @Description:
* @Author: WY
* @Date: 2025/5/14
**/
@Data
public class DeviceTypeQueryCriteria extends BaseEntity implements Serializable {
@Schema(name = "型号名称")
private String typeName;
@Schema(name = "所属客户")
private Set<Long> customerIds;
@Schema(name = "所属客户")
private Long customerId;
@Schema(name = "com.fuyuanshen")
private Long tenantId;
@Schema(name = "页码", example = "1")
private Integer page = 1;
@Schema(name = "每页数据量", example = "10")
private Integer size = 10;
}

View File

@ -1,48 +0,0 @@
package com.fuyuanshen.equipment.enums;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* 用户类型枚举
*
* @author: 默苍璃
* @date: 2025-06-1811:14
*/
public enum UserType {
APP(0, "APP"), MINI_PROGRAM(1, "小程序");
private final int value;
private final String description;
UserType(int value, String description) {
this.value = value;
this.description = description;
}
@JsonValue
public int getValue() {
return value;
}
public String getDescription() {
return description;
}
/**
* 根据值获取对应的枚举
*
* @param value 枚举值
* @return 对应的枚举对象
*/
public static UserType fromValue(int value) {
for (UserType userType : values()) {
if (userType.getValue() == value) {
return userType;
}
}
throw new IllegalArgumentException("Invalid user type value: " + value);
}
}

View File

@ -0,0 +1,39 @@
package com.fuyuanshen.equipment.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Description:
* @Author: WY
* @Date: 2025/5/14
**/
@Mapper
public interface DeviceTypeMapper extends BaseMapper<DeviceType> {
/**
* 分页查询设备类型
*
* @param criteria
* @param page
* @return
*/
IPage<DeviceType> findAll(@Param("criteria") DeviceTypeQueryCriteria criteria, Page<Object> page);
/**
* 查询所有设备类型
*
* @param criteria
* @return
*/
List<DeviceType> findAll(@Param("criteria") DeviceTypeQueryCriteria criteria);
}

View File

@ -0,0 +1,64 @@
package com.fuyuanshen.equipment.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import java.util.List;
/**
* @Description:
* @Author: WY
* @Date: 2025/5/14
**/
public interface DeviceTypeService extends IService<DeviceType> {
/**
* 查询数据分页
*
* @param criteria 条件
* @param page 分页参数
* @return PageResult
*/
PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page);
/**
* 查询所有数据不分页
*
* @param criteria 条件参数
* @return List<DeviceTypeDto>
*/
List<DeviceType> queryAll(DeviceTypeQueryCriteria criteria);
/**
* 查询所有设备类型
*
* @return
*/
List<DeviceType> queryDeviceTypes();
/**
* 新增设备类型
*
* @param resources /
*/
void create(DeviceType resources);
/**
* 编辑
*
* @param resources /
*/
void update(DeviceType resources);
/**
* 多选删除
*
* @param ids /
*/
void deleteAll(List<Long> ids);
}

View File

@ -0,0 +1,157 @@
package com.fuyuanshen.equipment.service.impl;
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.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import com.fuyuanshen.equipment.service.DeviceTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @Description:
* @Author: WY
* @Date: 2025/5/14
**/
@Service
@RequiredArgsConstructor
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements DeviceTypeService {
private final DeviceTypeMapper deviceTypeMapper;
private final DeviceMapper deviceMapper;
/**
* 分页查询设备类型
*
* @param criteria 条件
* @param page 分页参数
* @return
*/
@Override
public PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page) {
return PageUtil.toPage(deviceTypeMapper.findAll(criteria, page));
}
/**
* 查询所有设备类型
*
* @return
*/
@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) {
return deviceTypeMapper.findAll(criteria);
}
/**
* 新增设备类型
*
* @param resources /
*/
@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);
}
/**
* 修改设备类型
*
* @param resources /
*/
@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);
}
/**
* 删除设备类型
*
* @param ids /
*/
@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));
}
}

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceTypeMapper">
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.DeviceType">
<id column="id" property="id"/>
<result column="type_name" property="typeName"/>
<result column="is_support_ble" property="isSupportBle"/>
<result column="locate_mode" property="locateMode"/>
<result column="network_way" property="networkWay"/>
<result column="create_by" property="createBy"/>
<result column="update_by" property="updateBy"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="communication_mode" property="communicationMode"/>
</resultMap>
<sql id="Base_Column_List">
id
, type_name, is_support_ble, locate_mode, network_way, create_by, update_by, create_time, update_time,communication_mode
</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.*
FROM device_type dt
<where>
<if test="criteria.typeName != null and criteria.typeName.trim() != ''">
and dt.type_name like concat('%', TRIM(#{criteria.typeName}), '%')
</if>
<if test="criteria.tenantId != null">
and dt.tenant_id = #{criteria.tenantId}
</if>
<if test="criteria.createBy != null">
and dt.create_by = #{criteria.createBy}
</if>
</where>
ORDER BY dt.create_time DESC
</select>
</mapper>