refactor(iot): 重构产品和服务参数处理逻辑

- 移除 ProductParam 实体和相关操作
- 更新 Param 实体,增加 foreignType 和 foreignId 字段- 修改 ProductServiceImpl,使用 ParamService 处理参数
- 更新 Serve 实体,区分输入和输出参数
- 调整 ServeDto,分离 inputs 和 outputs
- 注释掉 JpaUserDetailsServiceImpl 中的权限查询代码
This commit is contained in:
zhuangtianxiang 2024-12-28 20:44:32 +08:00
parent a9c7236a4e
commit e1a027e55a
6 changed files with 51 additions and 67 deletions

View File

@ -40,7 +40,7 @@ public class JpaUserDetailsServiceImpl implements UserDetailsService {
}
// List<RoleAuthority> roleAuthorities= roleAuthoritiesRepository.selectByRoleId(user.getRoleId());
user.role.authorities = authorityRepository.selectAuthoritiesByRoleId(user.getRoleId());
// user.role.authorities = authorityRepository.selectAuthoritiesByRoleId(user.getRoleId());
List<Menu> menus = menuRepository.selectByRoleId(user.getRoleId());
Set<String> permissions = menus.stream().map(Menu::getPermissions).collect(Collectors.toSet());
return UserDetailsImpl.from(user, permissions);

View File

@ -6,14 +6,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsc.edu.gateway.exception.ConstraintException;
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
import com.zsc.edu.gateway.modules.iot.product.entity.ProductParam;
import com.zsc.edu.gateway.modules.iot.product.mapper.ProductMapper;
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
import com.zsc.edu.gateway.modules.iot.product.repo.ProductParamRepository;
import com.zsc.edu.gateway.modules.iot.product.repo.ProductRepository;
import com.zsc.edu.gateway.modules.iot.product.service.ProductService;
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
import com.zsc.edu.gateway.modules.iot.tsl.entity.EventParam;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
@ -34,7 +31,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
private final ProductMapper mapper;
private final ParamMapper paramMapper;
private final ParamRepository paramRepo;
private final ProductParamRepository productParamRepo;
private final ParamService paramService;
/**
@ -47,10 +43,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
}
Product product = mapper.toEntity(dto);
save(product);
List<ProductParam> productParams = paramService.paramCreate(dto.getParams()).stream()
.map(paramId -> new ProductParam(product.getId(), paramId))
.toList();
productParamRepo.insert(productParams);
paramService.create(dto.getParams(), product.getId(), Param.ForeignType.PRODUCT);
return product;
}
/**
@ -61,12 +54,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
Product product = baseMapper.selectById(id);
mapper.convert(dto, product);
updateById(product);
paramService.paramUpdate(dto.getParams(),
productParamRepo.selectList(new LambdaQueryWrapper<ProductParam>()
.eq(ProductParam::getProductId, product.getId()))
.stream()
.map(ProductParam::getParamId)
.collect(Collectors.toList()));
paramService.update(dto.getParams(), product.getId());
return product;
}
@ -91,16 +79,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
@Override
public boolean delete(Long id) {
removeById(id);
LambdaQueryWrapper<ProductParam> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductParam::getProductId, id);
List<ProductParam> productParams = productParamRepo.selectList(wrapper);
if (!productParams.isEmpty()) {
List<Long> paramIds = productParams.stream()
.map(ProductParam::getParamId)
.toList();
paramRepo.deleteByIds(paramIds);
}
productParamRepo.delete(wrapper);
paramService.delete(id);
return true;
}
}

View File

@ -21,9 +21,6 @@ public class ServeDto {
public String identifier;
private List<ParamDto> params;
//TODO 将inputs和outputs整合成一个params集合操作一样params中有type区分
// private List<ParamDto> inputs;
// private List<ParamDto> outputs;
private List<ParamDto> inputs;
private List<ParamDto> outputs;
}

View File

@ -32,11 +32,15 @@ public class Param extends BaseParam {
*/
private Type type;
// /**
// * 事件/服务/产品的类型
// */
// private ParamType paramType;
/**
* 联表的类型
*/
private ForeignType foreignType;
/**
* 联表的id
*/
private Long foreignId;
public enum Type implements IEnum<Integer>, IState<Type> {
/**
* 物模型输入
@ -70,36 +74,36 @@ public class Param extends BaseParam {
}
}
// public enum ParamType implements IEnum<Integer>, IState<ParamType> {
// /**
// * 事件
// */
// EVENT(1, "Event"),
// /**
// * 服务
// */
// SERVICE(2, "Service"),
// /**
// * 产品
// */
// PRODUCT(3, "Product");
//
// private final int value;
// private final String description;
//
// ParamType(int value, String description) {
// this.value = value;
// this.description = description;
// }
//
// @Override
// public Integer getValue() {
// return value;
// }
//
// @Override
// public String toString() {
// return this.description;
// }
// }
public enum ForeignType implements IEnum<Integer>, IState<ForeignType> {
/**
* 事件
*/
EVENT(1, "Event"),
/**
* 服务
*/
SERVE(2, "Service"),
/**
* 产品
*/
PRODUCT(3, "Product");
private final int value;
private final String description;
ForeignType(int value, String description) {
this.value = value;
this.description = description;
}
@Override
public Integer getValue() {
return value;
}
@Override
public String toString() {
return this.description;
}
}
}

View File

@ -2,6 +2,7 @@ package com.zsc.edu.gateway.modules.iot.tsl.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -27,7 +28,9 @@ public class Serve extends BaseParam {
* 服务输入/输出参数根据param中的type区分
*/
@TableField(exist = false)
private List<Param> params;
private List<ParamDto> inputs;
@TableField(exist = false)
private List<ParamDto> outputs;
}

View File

@ -39,6 +39,7 @@ public class UserServiceTest {
void test1() {
// User user=userRepository.selectByUsername("admin");
// System.out.println(user);
String admin = passwordEncoder.encode("admin");
System.out.println(admin);
}