fix(iot): 补充设备、事件和服务名称非空校验
- 在创建和更新设备、事件和服务时,增加了对名称非空的校验 - 抛出 ConstraintException 异常,提示名称不能为空 - 优化了数据完整性验证,防止非法数据入库
This commit is contained in:
parent
e1a027e55a
commit
75d640cf3c
@ -29,8 +29,6 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product> implements ProductService {
|
||||
private final ProductMapper mapper;
|
||||
private final ParamMapper paramMapper;
|
||||
private final ParamRepository paramRepo;
|
||||
private final ParamService paramService;
|
||||
|
||||
/**
|
||||
@ -41,6 +39,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该设备已存在!");
|
||||
}
|
||||
if (dto.getName() == null) {
|
||||
throw new ConstraintException("设备名称不能为空!");
|
||||
}
|
||||
Product product = mapper.toEntity(dto);
|
||||
save(product);
|
||||
paramService.create(dto.getParams(), product.getId(), Param.ForeignType.PRODUCT);
|
||||
@ -51,6 +52,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
||||
*/
|
||||
@Override
|
||||
public Product update(ProductDto dto, Long id) {
|
||||
if (dto.getName() == null) {
|
||||
throw new ConstraintException("设备名称不能为空!");
|
||||
}
|
||||
Product product = baseMapper.selectById(id);
|
||||
mapper.convert(dto, product);
|
||||
updateById(product);
|
||||
@ -58,16 +62,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
||||
return product;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 分页查询产品
|
||||
// *
|
||||
// * @param query 查询表单
|
||||
// * @param page 分页参数
|
||||
// */
|
||||
// @Override
|
||||
// public Page<Product> page(Page<Product> page, ProductQuery query) {
|
||||
// return baseMapper.page(page, query.wrapper());
|
||||
// }
|
||||
@Override
|
||||
public Product detail(Long id) {
|
||||
return baseMapper.selectById(id);
|
||||
|
@ -29,6 +29,9 @@ public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implem
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
}
|
||||
if (dto.getName() == null) {
|
||||
throw new ConstraintException("事件名称不能为空!");
|
||||
}
|
||||
Event event = mapper.toEntity(dto);
|
||||
save(event);
|
||||
paramService.create(dto.getOutputs(), event.getId(), Param.ForeignType.EVENT);
|
||||
@ -39,6 +42,9 @@ public class EventServiceImpl extends ServiceImpl<EventRepository, Event> implem
|
||||
*/
|
||||
@Override
|
||||
public Event update(EventDto dto, Long id) {
|
||||
if (dto.getName() == null) {
|
||||
throw new ConstraintException("事件名称不能为空!");
|
||||
}
|
||||
Event event = baseMapper.selectById(id);
|
||||
mapper.convert(dto, event);
|
||||
updateById(event);
|
||||
|
@ -31,7 +31,10 @@ public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implem
|
||||
@Override
|
||||
public Serve create(ServeDto dto) {
|
||||
if (baseMapper.findByName(dto.getName()) != null) {
|
||||
throw new ConstraintException("该事件已存在!");
|
||||
throw new ConstraintException("该服务已存在!");
|
||||
}
|
||||
if (dto.getName() == null) {
|
||||
throw new ConstraintException("服务名称不能为空!");
|
||||
}
|
||||
Serve serve = mapper.toEntity(dto);
|
||||
save(serve);
|
||||
@ -45,6 +48,9 @@ public class ServeServiceImpl extends ServiceImpl<ServeRepository, Serve> implem
|
||||
*/
|
||||
@Override
|
||||
public Serve update(ServeDto dto, Long id) {
|
||||
if (dto.getName() == null) {
|
||||
throw new ConstraintException("服务名称不能为空!");
|
||||
}
|
||||
Serve serve = baseMapper.selectById(id);
|
||||
mapper.convert(dto, serve);
|
||||
updateById(serve);
|
||||
|
Loading…
Reference in New Issue
Block a user