refactor(iot): 重构产品和服务参数处理逻辑
- 移除 ProductParam 实体和相关操作 - 更新 Param 实体,增加 foreignType 和 foreignId 字段- 修改 ProductServiceImpl,使用 ParamService 处理参数 - 更新 Serve 实体,区分输入和输出参数 - 调整 ServeDto,分离 inputs 和 outputs - 注释掉 JpaUserDetailsServiceImpl 中的权限查询代码
This commit is contained in:
parent
a9c7236a4e
commit
e1a027e55a
@ -40,7 +40,7 @@ public class JpaUserDetailsServiceImpl implements UserDetailsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List<RoleAuthority> roleAuthorities= roleAuthoritiesRepository.selectByRoleId(user.getRoleId());
|
// 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());
|
List<Menu> menus = menuRepository.selectByRoleId(user.getRoleId());
|
||||||
Set<String> permissions = menus.stream().map(Menu::getPermissions).collect(Collectors.toSet());
|
Set<String> permissions = menus.stream().map(Menu::getPermissions).collect(Collectors.toSet());
|
||||||
return UserDetailsImpl.from(user, permissions);
|
return UserDetailsImpl.from(user, permissions);
|
||||||
|
@ -6,14 +6,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
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.dto.ProductDto;
|
||||||
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
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.mapper.ProductMapper;
|
||||||
import com.zsc.edu.gateway.modules.iot.product.query.ProductQuery;
|
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.repo.ProductRepository;
|
||||||
import com.zsc.edu.gateway.modules.iot.product.service.ProductService;
|
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.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.entity.Param;
|
||||||
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
|
import com.zsc.edu.gateway.modules.iot.tsl.mapper.ParamMapper;
|
||||||
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
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 ProductMapper mapper;
|
||||||
private final ParamMapper paramMapper;
|
private final ParamMapper paramMapper;
|
||||||
private final ParamRepository paramRepo;
|
private final ParamRepository paramRepo;
|
||||||
private final ProductParamRepository productParamRepo;
|
|
||||||
private final ParamService paramService;
|
private final ParamService paramService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,10 +43,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
|||||||
}
|
}
|
||||||
Product product = mapper.toEntity(dto);
|
Product product = mapper.toEntity(dto);
|
||||||
save(product);
|
save(product);
|
||||||
List<ProductParam> productParams = paramService.paramCreate(dto.getParams()).stream()
|
paramService.create(dto.getParams(), product.getId(), Param.ForeignType.PRODUCT);
|
||||||
.map(paramId -> new ProductParam(product.getId(), paramId))
|
|
||||||
.toList();
|
|
||||||
productParamRepo.insert(productParams);
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -61,12 +54,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
|||||||
Product product = baseMapper.selectById(id);
|
Product product = baseMapper.selectById(id);
|
||||||
mapper.convert(dto, product);
|
mapper.convert(dto, product);
|
||||||
updateById(product);
|
updateById(product);
|
||||||
paramService.paramUpdate(dto.getParams(),
|
paramService.update(dto.getParams(), product.getId());
|
||||||
productParamRepo.selectList(new LambdaQueryWrapper<ProductParam>()
|
|
||||||
.eq(ProductParam::getProductId, product.getId()))
|
|
||||||
.stream()
|
|
||||||
.map(ProductParam::getParamId)
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,16 +79,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
|||||||
@Override
|
@Override
|
||||||
public boolean delete(Long id) {
|
public boolean delete(Long id) {
|
||||||
removeById(id);
|
removeById(id);
|
||||||
LambdaQueryWrapper<ProductParam> wrapper = new LambdaQueryWrapper<>();
|
paramService.delete(id);
|
||||||
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);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,6 @@ public class ServeDto {
|
|||||||
|
|
||||||
public String identifier;
|
public String identifier;
|
||||||
|
|
||||||
private List<ParamDto> params;
|
private List<ParamDto> inputs;
|
||||||
|
private List<ParamDto> outputs;
|
||||||
//TODO 将inputs和outputs整合成一个params集合(操作一样,params中有type区分)
|
|
||||||
// private List<ParamDto> inputs;
|
|
||||||
// private List<ParamDto> outputs;
|
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,15 @@ public class Param extends BaseParam {
|
|||||||
*/
|
*/
|
||||||
private Type type;
|
private Type type;
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * 事件/服务/产品的类型
|
* 联表的类型
|
||||||
// */
|
*/
|
||||||
// private ParamType paramType;
|
private ForeignType foreignType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联表的id
|
||||||
|
*/
|
||||||
|
private Long foreignId;
|
||||||
public enum Type implements IEnum<Integer>, IState<Type> {
|
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> {
|
public enum ForeignType implements IEnum<Integer>, IState<ForeignType> {
|
||||||
// /**
|
/**
|
||||||
// * 事件
|
* 事件
|
||||||
// */
|
*/
|
||||||
// EVENT(1, "Event"),
|
EVENT(1, "Event"),
|
||||||
// /**
|
/**
|
||||||
// * 服务
|
* 服务
|
||||||
// */
|
*/
|
||||||
// SERVICE(2, "Service"),
|
SERVE(2, "Service"),
|
||||||
// /**
|
/**
|
||||||
// * 产品
|
* 产品
|
||||||
// */
|
*/
|
||||||
// PRODUCT(3, "Product");
|
PRODUCT(3, "Product");
|
||||||
//
|
|
||||||
// private final int value;
|
private final int value;
|
||||||
// private final String description;
|
private final String description;
|
||||||
//
|
|
||||||
// ParamType(int value, String description) {
|
ForeignType(int value, String description) {
|
||||||
// this.value = value;
|
this.value = value;
|
||||||
// this.description = description;
|
this.description = description;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public Integer getValue() {
|
public Integer getValue() {
|
||||||
// return value;
|
return value;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public String toString() {
|
public String toString() {
|
||||||
// return this.description;
|
return this.description;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.zsc.edu.gateway.modules.iot.tsl.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -27,7 +28,9 @@ public class Serve extends BaseParam {
|
|||||||
* 服务输入/输出参数,根据param中的type区分
|
* 服务输入/输出参数,根据param中的type区分
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<Param> params;
|
private List<ParamDto> inputs;
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<ParamDto> outputs;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ public class UserServiceTest {
|
|||||||
void test1() {
|
void test1() {
|
||||||
// User user=userRepository.selectByUsername("admin");
|
// User user=userRepository.selectByUsername("admin");
|
||||||
// System.out.println(user);
|
// System.out.println(user);
|
||||||
|
|
||||||
String admin = passwordEncoder.encode("admin");
|
String admin = passwordEncoder.encode("admin");
|
||||||
System.out.println(admin);
|
System.out.println(admin);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user