feat IJPACommData基础数据操作接口

V0.5.x
jay 2023-06-01 14:05:55 +08:00
parent eda4285368
commit f3895c458c
20 changed files with 249 additions and 676 deletions

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.dao;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.ICommonData;
import cc.iotkit.data.util.PageBuilder;
import cc.iotkit.data.util.PredicateBuilder;
@ -23,17 +24,23 @@ import java.util.Optional;
* @Version: V1.0
* @Description:
*/
public interface IJPACommData<T extends Id<ID>, ID> extends ICommonData<T , ID> {
public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID> {
JpaRepository getBaseRepository();
Class getJpaRepositoryClass();
@Override
default T findById(ID id) {
return (T)getBaseRepository().findById(id).orElse(null);
}
@Override
default List<T> findByIds(Collection<ID> id) {
List allById = getBaseRepository().findAllById(id);
@ -42,13 +49,13 @@ public interface IJPACommData<T extends Id<ID>, ID> extends ICommonData<T , ID>
@Override
default T save(T data) {
Object o = getBaseRepository().save(data);
Object o = getBaseRepository().save(MapstructUtils.convert(data, getJpaRepositoryClass()));
return (T) o;
}
@Override
default void batchSave(List<T> data) {
getBaseRepository().saveAll(data);
getBaseRepository().saveAll(MapstructUtils.convert(data, getJpaRepositoryClass()));
}
@Override
@ -103,7 +110,7 @@ public interface IJPACommData<T extends Id<ID>, ID> extends ICommonData<T , ID>
default Example genExample(T data) {
return Example.of(data);
return Example.of(MapstructUtils.convert(data, getJpaRepositoryClass()));
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IAlertConfigData;
import cc.iotkit.data.dao.AlertConfigRepository;
import cc.iotkit.data.model.TbAlertConfig;
@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -20,70 +22,27 @@ import java.util.UUID;
@Primary
@Service
public class AlertConfigDataImpl implements IAlertConfigData {
public class AlertConfigDataImpl implements IAlertConfigData, IJPACommData<AlertConfig, String> {
@Autowired
private AlertConfigRepository alertConfigRepository;
@Override
public AlertConfig findById(String s) {
return null;
public JpaRepository getBaseRepository() {
return alertConfigRepository;
}
@Override
public List<AlertConfig> findByIds(Collection<String> id) {
return null;
}
@Override
public AlertConfig save(AlertConfig data) {
alertConfigRepository.save(MapstructUtils.convert(data, TbAlertConfig.class));
return data;
}
@Override
public void batchSave(List<AlertConfig> data) {
}
@Override
public void deleteById(String s) {
alertConfigRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
public Class getJpaRepositoryClass() {
return TbAlertConfig.class;
}
@Override
public long count() {
return 0;
}
@Override
public List<AlertConfig> findAll() {
return null;
}
@Override
public Paging<AlertConfig> findAll(PageRequest<AlertConfig> pageRequest) {
return null;
}
@Override
public List<AlertConfig> findAllByCondition(AlertConfig data) {
return null;
}
@Override
public AlertConfig findOneByCondition(AlertConfig data) {
return null;
}
@Override

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IAlertRecordData;
import cc.iotkit.data.dao.AlertRecordRepository;
import cc.iotkit.data.model.TbAlertRecord;
@ -15,74 +16,27 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
@Primary
@Service
public class AlertRecordDataImpl implements IAlertRecordData {
public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData<AlertRecord, String> {
@Autowired
private AlertRecordRepository alertRecordRepository;
@Override
public AlertRecord findById(String s) {
return null;
public JpaRepository getBaseRepository() {
return alertRecordRepository;
}
@Override
public List<AlertRecord> findByIds(Collection<String> id) {
return null;
public Class getJpaRepositoryClass() {
return TbAlertRecord.class;
}
@Override
public AlertRecord save(AlertRecord data) {
return null;
}
@Override
public void batchSave(List<AlertRecord> data) {
}
@Override
public void deleteById(String s) {
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return 0;
}
@Override
public List<AlertRecord> findAll() {
return null;
}
@Override
public Paging<AlertRecord> findAll(PageRequest<AlertRecord> pageRequest) {
return null;
}
@Override
public List<AlertRecord> findAllByCondition(AlertRecord data) {
return null;
}
@Override
public AlertRecord findOneByCondition(AlertRecord data) {
return null;
}
@Override
public Paging<AlertRecord> selectAlertConfigPage(PageRequest<AlertRecord> request) {

View File

@ -11,6 +11,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.ICategoryData;
import cc.iotkit.data.dao.CategoryRepository;
import cc.iotkit.data.model.TbCategory;
@ -19,6 +20,7 @@ import cc.iotkit.model.product.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -27,11 +29,21 @@ import java.util.stream.Collectors;
@Primary
@Service
public class CategoryDataImpl implements ICategoryData {
public class CategoryDataImpl implements ICategoryData, IJPACommData<Category, String> {
@Autowired
private CategoryRepository categoryRepository;
@Override
public JpaRepository getBaseRepository() {
return categoryRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbCategory.class;
}
@Override
public Category findById(String s) {
return MapstructUtils.convert(categoryRepository.findById(s).orElse(null), Category.class);
@ -49,20 +61,7 @@ public class CategoryDataImpl implements ICategoryData {
return data;
}
@Override
public void batchSave(List<Category> data) {
}
@Override
public void deleteById(String s) {
categoryRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@ -78,21 +77,6 @@ public class CategoryDataImpl implements ICategoryData {
.collect(Collectors.toList());
}
@Override
public Paging<Category> findAll(PageRequest<Category> pageRequest) {
return null;
}
@Override
public List<Category> findAllByCondition(Category data) {
return null;
}
@Override
public Category findOneByCondition(Category data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IChannelConfigData;
import cc.iotkit.data.dao.ChannelConfigRepository;
import cc.iotkit.data.model.TbChannelConfig;
@ -11,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -25,11 +27,21 @@ import java.util.UUID;
**/
@Primary
@Service
public class ChannelConfigDataImpl implements IChannelConfigData {
public class ChannelConfigDataImpl implements IChannelConfigData, IJPACommData<ChannelConfig, String> {
@Resource
private ChannelConfigRepository channelConfigRepository;
@Override
public JpaRepository getBaseRepository() {
return channelConfigRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbChannelConfig.class;
}
@Override
public ChannelConfig findById(String id) {
return MapstructUtils.convert(channelConfigRepository.findById(id).orElse(null), ChannelConfig.class);
@ -49,46 +61,5 @@ public class ChannelConfigDataImpl implements IChannelConfigData {
return data;
}
@Override
public void batchSave(List<ChannelConfig> data) {
}
@Override
public void deleteById(String id) {
channelConfigRepository.deleteById(id);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return channelConfigRepository.count();
}
@Override
public List<ChannelConfig> findAll() {
return MapstructUtils.convert(channelConfigRepository.findAll(), ChannelConfig.class);
}
@Override
public Paging<ChannelConfig> findAll(PageRequest<ChannelConfig> pageRequest) {
return null;
}
@Override
public List<ChannelConfig> findAllByCondition(ChannelConfig data) {
return null;
}
@Override
public ChannelConfig findOneByCondition(ChannelConfig data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IChannelData;
import cc.iotkit.data.dao.ChannelRepository;
import cc.iotkit.data.model.TbChannel;
@ -11,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -25,20 +27,26 @@ import java.util.UUID;
**/
@Primary
@Service
public class ChannelDataImpl implements IChannelData {
public class ChannelDataImpl implements IChannelData, IJPACommData<Channel, String> {
@Resource
private ChannelRepository channelRepository;
@Override
public JpaRepository getBaseRepository() {
return channelRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbChannel.class;
}
@Override
public Channel findById(String id) {
return MapstructUtils.convert(channelRepository.findById(id).orElse(null), Channel.class);
}
@Override
public List<Channel> findByIds(Collection<String> id) {
return null;
}
@Override
public Channel save(Channel data) {
@ -51,47 +59,12 @@ public class ChannelDataImpl implements IChannelData {
return data;
}
@Override
public void batchSave(List<Channel> data) {
}
@Override
public void deleteById(String id) {
channelRepository.deleteById(id);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return channelRepository.count();
}
@Override
public List<Channel> findAll() {
return MapstructUtils.convert(channelRepository.findAll(), Channel.class);
}
@Override
public Paging<Channel> findAll(PageRequest<Channel> pageRequest) {
return null;
}
@Override
public List<Channel> findAllByCondition(Channel data) {
return null;
}
@Override
public Channel findOneByCondition(Channel data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IChannelTemplateData;
import cc.iotkit.data.dao.ChannelTemplateRepository;
import cc.iotkit.data.model.TbChannelTemplate;
@ -11,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -26,11 +28,21 @@ import java.util.stream.Collectors;
**/
@Primary
@Service
public class ChannelTemplateDataImpl implements IChannelTemplateData {
public class ChannelTemplateDataImpl implements IChannelTemplateData, IJPACommData<ChannelTemplate, String> {
@Resource
private ChannelTemplateRepository channelTemplateRepository;
@Override
public JpaRepository getBaseRepository() {
return channelTemplateRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbChannelTemplate.class;
}
@Override
public ChannelTemplate findById(String id) {
return MapstructUtils.convert(channelTemplateRepository.findById(id).orElse(null), ChannelTemplate.class);

View File

@ -53,15 +53,10 @@ public class DeviceConfigDataImpl implements IDeviceConfigData, IJPACommData<Dev
}
@Override
public DeviceConfig findById(String s) {
return MapstructUtils.convert(deviceConfigRepository.findById(s).orElse(null), DeviceConfig.class);
public Class getJpaRepositoryClass() {
return TbDeviceConfig.class;
}
@Override
public List<DeviceConfig> findByIds(Collection<String> ids) {
List<TbDeviceConfig> allById = deviceConfigRepository.findAllById(ids);
return MapstructUtils.convert(allById, DeviceConfig.class);
}
@Override
public DeviceConfig save(DeviceConfig data) {
@ -72,32 +67,6 @@ public class DeviceConfigDataImpl implements IDeviceConfigData, IJPACommData<Dev
return data;
}
@Override
public void batchSave(List<DeviceConfig> data) {
deviceConfigRepository.saveAll(IteratorUtils.toList(data.iterator()));
}
@Override
public void deleteById(String s) {
deviceConfigRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> ids) {
deviceConfigRepository.deleteAllById(ids);
}
@Override
public long count() {
return deviceConfigRepository.count();
}
@Override
public List<DeviceConfig> findAll() {
return MapstructUtils.convert(deviceConfigRepository.findAll(), DeviceConfig.class);
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IDeviceGroupData;
import cc.iotkit.data.dao.DeviceGroupRepository;
import cc.iotkit.data.model.TbDeviceGroup;
@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -20,11 +22,21 @@ import java.util.UUID;
@Primary
@Service
public class DeviceGroupDataImpl implements IDeviceGroupData {
public class DeviceGroupDataImpl implements IDeviceGroupData, IJPACommData<DeviceGroup, String> {
@Autowired
private DeviceGroupRepository deviceGroupRepository;
@Override
public JpaRepository getBaseRepository() {
return deviceGroupRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbDeviceGroup.class;
}
@Override
public Paging<DeviceGroup> findByNameLike(String name, int page, int size) {
Page<TbDeviceGroup> groups = deviceGroupRepository.findByNameLike("%" + name.trim() + "%",
@ -33,16 +45,12 @@ public class DeviceGroupDataImpl implements IDeviceGroupData {
MapstructUtils.convert(groups.getContent(), DeviceGroup.class));
}
@Override
public DeviceGroup findById(String s) {
return MapstructUtils.convert(deviceGroupRepository.findById(s).orElse(null), DeviceGroup.class);
}
@Override
public List<DeviceGroup> findByIds(Collection<String> id) {
return null;
}
@Override
public DeviceGroup save(DeviceGroup data) {
if (StringUtils.isBlank(data.getId())) {
@ -52,47 +60,11 @@ public class DeviceGroupDataImpl implements IDeviceGroupData {
return data;
}
@Override
public void batchSave(List<DeviceGroup> data) {
}
@Override
public void deleteById(String s) {
deviceGroupRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return deviceGroupRepository.count();
}
@Override
public List<DeviceGroup> findAll() {
return MapstructUtils.convert(deviceGroupRepository.findAll(), DeviceGroup.class);
}
@Override
public Paging<DeviceGroup> findAll(PageRequest<DeviceGroup> pageRequest) {
return null;
}
@Override
public List<DeviceGroup> findAllByCondition(DeviceGroup data) {
return null;
}
@Override
public DeviceGroup findOneByCondition(DeviceGroup data) {
return null;
}
}

View File

@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -31,7 +32,7 @@ import java.util.stream.Collectors;
@Primary
@Service
public class DeviceInfoDataImpl implements IDeviceInfoData {
public class DeviceInfoDataImpl implements IDeviceInfoData,IJPACommData<DeviceInfo, String> {
@Autowired
private DeviceInfoRepository deviceInfoRepository;
@ -52,6 +53,16 @@ public class DeviceInfoDataImpl implements IDeviceInfoData {
@Qualifier("categoryDataCache")
private ICategoryData categoryData;
@Override
public JpaRepository getBaseRepository() {
return deviceInfoRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbDeviceInfo.class;
}
@Override
public void saveProperties(String deviceId, Map<String, Object> properties) {
}
@ -426,6 +437,8 @@ public class DeviceInfoDataImpl implements IDeviceInfoData {
return 0;
}
@Override
public DeviceInfo findById(String s) {
return DeviceInfoMapper.M.toDto(

View File

@ -31,6 +31,11 @@ public class HomeDataImpl implements IHomeData, IJPACommData<Home, String> {
return homeRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbHome.class;
}
@Override
public Home findByUidAndCurrent(String uid, boolean current) {
return MapstructUtils.convert(homeRepository.findByUidAndCurrent(uid, current), Home.class);
@ -46,10 +51,6 @@ public class HomeDataImpl implements IHomeData, IJPACommData<Home, String> {
return MapstructUtils.convert(homeRepository.findByUid(uid), Home.class);
}
@Override
public Paging<Home> findByUid(String uid, int page, int size) {
return null;
}
@Override
public long countByUid(String uid) {
@ -71,48 +72,7 @@ public class HomeDataImpl implements IHomeData, IJPACommData<Home, String> {
return data;
}
@Override
public void batchSave(List<Home> data) {
}
@Override
public void deleteById(String s) {
homeRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return homeRepository.count();
}
@Override
public List<Home> findAll() {
return MapstructUtils.convert(homeRepository.findAll(), Home.class);
}
@Override
public Paging<Home> findAll(PageRequest<Home> pageRequest) {
return null;
}
@Override
public List<Home> findAllByCondition(Home data) {
return null;
}
@Override
public Home findOneByCondition(Home data) {
return null;
}
}

View File

@ -11,6 +11,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IOauthClientData;
import cc.iotkit.data.dao.OauthClientRepository;
import cc.iotkit.data.model.TbOauthClient;
@ -19,6 +20,7 @@ import cc.iotkit.common.api.Paging;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -28,7 +30,7 @@ import java.util.UUID;
@Primary
@Service
public class OauthClientDataImpl implements IOauthClientData {
public class OauthClientDataImpl implements IOauthClientData, IJPACommData<OauthClient, String> {
@Autowired
private OauthClientRepository oauthClientRepository;
@ -38,15 +40,21 @@ public class OauthClientDataImpl implements IOauthClientData {
return MapstructUtils.convert(oauthClientRepository.findByClientId(clientId), OauthClient.class);
}
@Override
public JpaRepository getBaseRepository() {
return oauthClientRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbOauthClient.class;
}
@Override
public OauthClient findById(String s) {
return MapstructUtils.convert(oauthClientRepository.findById(s).orElse(null), OauthClient.class);
}
@Override
public List<OauthClient> findByIds(Collection<String> id) {
return null;
}
@Override
public OauthClient save(OauthClient data) {
@ -58,46 +66,8 @@ public class OauthClientDataImpl implements IOauthClientData {
return data;
}
@Override
public void batchSave(List<OauthClient> data) {
}
@Override
public void deleteById(String s) {
oauthClientRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return oauthClientRepository.count();
}
@Override
public List<OauthClient> findAll() {
return new ArrayList<>();
}
@Override
public Paging<OauthClient> findAll(PageRequest<OauthClient> pageRequest) {
return null;
}
@Override
public List<OauthClient> findAllByCondition(OauthClient data) {
return null;
}
@Override
public OauthClient findOneByCondition(OauthClient data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IProductData;
import cc.iotkit.data.dao.ProductRepository;
import cc.iotkit.data.model.TbProduct;
@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -18,11 +20,20 @@ import java.util.List;
@Primary
@Service
public class ProductDataImpl implements IProductData {
public class ProductDataImpl implements IProductData, IJPACommData<Product, String> {
@Autowired
private ProductRepository productRepository;
@Override
public JpaRepository getBaseRepository() {
return productRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbProduct.class;
}
@Override
public List<Product> findByCategory(String category) {
@ -47,15 +58,12 @@ public class ProductDataImpl implements IProductData {
return productRepository.countByUid(uid);
}
@Override
public Product findById(String s) {
return MapstructUtils.convert(productRepository.findById(s).orElse(null), Product.class);
}
@Override
public List<Product> findByIds(Collection<String> id) {
return null;
}
@Override
public Product save(Product data) {
@ -63,48 +71,5 @@ public class ProductDataImpl implements IProductData {
return data;
}
@Override
public void batchSave(List<Product> data) {
}
@Override
public void deleteById(String s) {
productRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return productRepository.count();
}
@Override
public List<Product> findAll() {
return MapstructUtils.convert(productRepository.findAll(), Product.class);
}
@Override
public Paging<Product> findAll(PageRequest<Product> pageRequest) {
return null;
}
@Override
public List<Product> findAllByCondition(Product data) {
return null;
}
@Override
public Product findOneByCondition(Product data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IProductModelData;
import cc.iotkit.data.dao.ProductModelRepository;
import cc.iotkit.data.model.TbProductModel;
@ -10,6 +11,7 @@ import cc.iotkit.model.product.ProductModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -19,11 +21,22 @@ import java.util.UUID;
@Primary
@Service
public class ProductModelDataImpl implements IProductModelData {
public class ProductModelDataImpl implements IProductModelData, IJPACommData<ProductModel, String> {
@Autowired
private ProductModelRepository productModelRepository;
@Override
public JpaRepository getBaseRepository() {
return productModelRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbProductModel.class;
}
@Override
public ProductModel findByModel(String model) {
return MapstructUtils.convert(productModelRepository.findByModel(model), ProductModel.class);
@ -54,45 +67,6 @@ public class ProductModelDataImpl implements IProductModelData {
return null;
}
@Override
public void batchSave(List<ProductModel> data) {
}
@Override
public void deleteById(String s) {
productModelRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return productModelRepository.count();
}
@Override
public List<ProductModel> findAll() {
return new ArrayList<>();
}
@Override
public Paging<ProductModel> findAll(PageRequest<ProductModel> pageRequest) {
return null;
}
@Override
public List<ProductModel> findAllByCondition(ProductModel data) {
return null;
}
@Override
public ProductModel findOneByCondition(ProductModel data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IProtocolComponentData;
import cc.iotkit.data.dao.ProtocolComponentRepository;
import cc.iotkit.data.model.TbProtocolComponent;
@ -16,6 +17,7 @@ import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -26,11 +28,21 @@ import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
@Primary
@Service
public class ProtocolComponentDataImpl implements IProtocolComponentData {
public class ProtocolComponentDataImpl implements IProtocolComponentData, IJPACommData<ProtocolComponent, String> {
@Autowired
private ProtocolComponentRepository protocolComponentRepository;
@Override
public JpaRepository getBaseRepository() {
return protocolComponentRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbProtocolComponent.class;
}
@Override
public List<ProtocolComponent> findByState(String state) {
return MapstructUtils.convert(protocolComponentRepository.findByState(state), ProtocolComponent.class);
@ -79,29 +91,11 @@ public class ProtocolComponentDataImpl implements IProtocolComponentData {
return data;
}
@Override
public void batchSave(List<ProtocolComponent> data) {
}
@Override
public void deleteById(String s) {
protocolComponentRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return protocolComponentRepository.count();
}
@Override
public List<ProtocolComponent> findAll() {
return MapstructUtils.convert(protocolComponentRepository.findAll(), ProtocolComponent.class);
@ -116,15 +110,7 @@ public class ProtocolComponentDataImpl implements IProtocolComponentData {
return new Paging<>(all.getTotalElements(), MapstructUtils.convert(all.getContent(), ProtocolComponent.class));
}
@Override
public List<ProtocolComponent> findAllByCondition(ProtocolComponent data) {
return null;
}
@Override
public ProtocolComponent findOneByCondition(ProtocolComponent data) {
return null;
}
}

View File

@ -11,6 +11,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IProtocolConverterData;
import cc.iotkit.data.dao.ProtocolConverterRepository;
import cc.iotkit.data.model.TbProtocolConverter;
@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -29,11 +31,21 @@ import java.util.UUID;
@Primary
@Service
public class ProtocolConverterDataImpl implements IProtocolConverterData {
public class ProtocolConverterDataImpl implements IProtocolConverterData, IJPACommData<ProtocolConverter, String> {
@Autowired
private ProtocolConverterRepository protocolConverterRepository;
@Override
public JpaRepository getBaseRepository() {
return protocolConverterRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbProtocolConverter.class;
}
@Override
public List<ProtocolConverter> findByUid(String uid) {
return MapstructUtils.convert(protocolConverterRepository.findByUid(uid), ProtocolConverter.class);
@ -52,6 +64,8 @@ public class ProtocolConverterDataImpl implements IProtocolConverterData {
return protocolConverterRepository.countByUid(uid);
}
@Override
public ProtocolConverter findById(String s) {
return MapstructUtils.convert(
@ -73,47 +87,5 @@ public class ProtocolConverterDataImpl implements IProtocolConverterData {
return data;
}
@Override
public void batchSave(List<ProtocolConverter> data) {
}
@Override
public void deleteById(String s) {
protocolConverterRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return protocolConverterRepository.count();
}
@Override
public List<ProtocolConverter> findAll() {
return MapstructUtils.convert(protocolConverterRepository.findAll(), ProtocolConverter.class);
}
@Override
public Paging<ProtocolConverter> findAll(PageRequest<ProtocolConverter> pageRequest) {
return null;
}
@Override
public List<ProtocolConverter> findAllByCondition(ProtocolConverter data) {
return null;
}
@Override
public ProtocolConverter findOneByCondition(ProtocolConverter data) {
return null;
}
}

View File

@ -10,6 +10,7 @@
package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.IRuleInfoData;
import cc.iotkit.data.dao.RuleInfoRepository;
import cc.iotkit.data.model.TbRuleInfo;
@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -29,11 +31,21 @@ import java.util.UUID;
@Primary
@Service
public class RuleInfoDataImpl implements IRuleInfoData {
public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData<RuleInfo, String> {
@Autowired
private RuleInfoRepository ruleInfoRepository;
@Override
public JpaRepository getBaseRepository() {
return ruleInfoRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbRuleInfo.class;
}
@Override
public List<RuleInfo> findByUidAndType(String uid, String type) {
return RuleInfoMapper.toDto(ruleInfoRepository.findByUidAndType(uid, type));
@ -73,6 +85,7 @@ public class RuleInfoDataImpl implements IRuleInfoData {
return ruleInfoRepository.countByUid(uid);
}
@Override
public RuleInfo findById(String s) {
return RuleInfoMapper.toDtoFix(ruleInfoRepository.findById(s).orElse(null));
@ -93,47 +106,5 @@ public class RuleInfoDataImpl implements IRuleInfoData {
return data;
}
@Override
public void batchSave(List<RuleInfo> data) {
}
@Override
public void deleteById(String s) {
ruleInfoRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return ruleInfoRepository.count();
}
@Override
public List<RuleInfo> findAll() {
return RuleInfoMapper.toDto(ruleInfoRepository.findAll());
}
@Override
public Paging<RuleInfo> findAll(PageRequest<RuleInfo> pageRequest) {
return null;
}
@Override
public List<RuleInfo> findAllByCondition(RuleInfo data) {
return null;
}
@Override
public RuleInfo findOneByCondition(RuleInfo data) {
return null;
}
}

View File

@ -2,6 +2,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.ISpaceData;
import cc.iotkit.data.dao.SpaceRepository;
import cc.iotkit.data.model.TbSpace;
@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -20,11 +22,22 @@ import java.util.UUID;
@Primary
@Service
public class SpaceDataImpl implements ISpaceData {
public class SpaceDataImpl implements ISpaceData, IJPACommData<Space, String> {
@Autowired
private SpaceRepository spaceRepository;
@Override
public JpaRepository getBaseRepository() {
return spaceRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbSpace.class;
}
@Override
public List<Space> findByUidOrderByCreateAtDesc(String uid) {
return MapstructUtils.convert(spaceRepository.findByUidOrderByCreateAtDesc(uid), Space.class);
@ -58,15 +71,13 @@ public class SpaceDataImpl implements ISpaceData {
return 0;
}
@Override
public Space findById(String s) {
return MapstructUtils.convert(spaceRepository.findById(s).orElse(null), Space.class);
}
@Override
public List<Space> findByIds(Collection<String> id) {
return null;
}
@Override
public Space save(Space data) {
@ -77,47 +88,6 @@ public class SpaceDataImpl implements ISpaceData {
return data;
}
@Override
public void batchSave(List<Space> data) {
}
@Override
public void deleteById(String s) {
spaceRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return spaceRepository.count();
}
@Override
public List<Space> findAll() {
return MapstructUtils.convert(spaceRepository.findAll(), Space.class);
}
@Override
public Paging<Space> findAll(PageRequest<Space> pageRequest) {
return null;
}
@Override
public List<Space> findAllByCondition(Space data) {
return null;
}
@Override
public Space findOneByCondition(Space data) {
return null;
}
}

View File

@ -11,6 +11,7 @@ package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.manager.ISpaceDeviceData;
import cc.iotkit.data.dao.SpaceDeviceRepository;
import cc.iotkit.data.model.TbSpaceDevice;
@ -19,6 +20,7 @@ import cc.iotkit.model.space.SpaceDevice;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -27,11 +29,22 @@ import java.util.UUID;
@Primary
@Service
public class SpaceDeviceDataImpl implements ISpaceDeviceData {
public class SpaceDeviceDataImpl implements ISpaceDeviceData, IJPACommData<SpaceDevice, String> {
@Autowired
private SpaceDeviceRepository spaceDeviceRepository;
@Override
public JpaRepository getBaseRepository() {
return spaceDeviceRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbSpaceDevice.class;
}
@Override
public List<SpaceDevice> findByUidOrderByUseAtDesc(String uid) {
return MapstructUtils.convert(spaceDeviceRepository.findByUidOrderByUseAtDesc(uid), SpaceDevice.class);
@ -82,15 +95,14 @@ public class SpaceDeviceDataImpl implements ISpaceDeviceData {
return 0;
}
@Override
public SpaceDevice findById(String s) {
return MapstructUtils.convert(spaceDeviceRepository.findById(s).orElse(null), SpaceDevice.class);
}
@Override
public List<SpaceDevice> findByIds(Collection<String> id) {
return null;
}
@Override
public SpaceDevice save(SpaceDevice data) {
@ -102,46 +114,13 @@ public class SpaceDeviceDataImpl implements ISpaceDeviceData {
return data;
}
@Override
public void batchSave(List<SpaceDevice> data) {
}
@Override
public void deleteById(String s) {
spaceDeviceRepository.deleteById(s);
}
@Override
public void deleteByIds(Collection<String> strings) {
}
@Override
public long count() {
return spaceDeviceRepository.count();
}
@Override
public List<SpaceDevice> findAll() {
return MapstructUtils.convert(spaceDeviceRepository.findAll(), SpaceDevice.class);
}
@Override
public Paging<SpaceDevice> findAll(PageRequest<SpaceDevice> pageRequest) {
return null;
}
@Override
public List<SpaceDevice> findAllByCondition(SpaceDevice data) {
return null;
}
@Override
public SpaceDevice findOneByCondition(SpaceDevice data) {
return null;
}
}

View File

@ -7,6 +7,7 @@ import cc.iotkit.common.enums.ErrCode;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.dao.SysConfigRepository;
import cc.iotkit.data.model.TbSysConfig;
import cc.iotkit.data.system.ISysConfigData;
@ -18,6 +19,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.IteratorUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -29,27 +31,37 @@ import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
@Primary
@Service
@RequiredArgsConstructor
public class SysConfigDataImpl implements ISysConfigData {
public class SysConfigDataImpl implements ISysConfigData, IJPACommData<SysConfig, Long> {
private final SysConfigRepository alertConfigRepository;
private final SysConfigRepository baseRepository;
@Override
public JpaRepository getBaseRepository() {
return baseRepository;
}
@Override
public Class getJpaRepositoryClass() {
return TbSysConfig.class;
}
@Override
public SysConfig findById(Long id) {
TbSysConfig tbSysConfig = alertConfigRepository.findById(id).orElseThrow(() ->
TbSysConfig tbSysConfig = baseRepository.findById(id).orElseThrow(() ->
new BizException(ErrCode.DATA_NOT_EXIST));
return MapstructUtils.convert(tbSysConfig, SysConfig.class);
}
@Override
public SysConfig save(SysConfig data) {
alertConfigRepository.save(MapstructUtils.convert(data, TbSysConfig.class));
baseRepository.save(MapstructUtils.convert(data, TbSysConfig.class));
return data;
}
@Override
public List<SysConfig> findByIds(Collection<Long> id) {
Iterable<TbSysConfig> allById = alertConfigRepository.findAllById(id);
Iterable<TbSysConfig> allById = baseRepository.findAllById(id);
Iterator<TbSysConfig> iterator = allById.iterator();
return MapstructUtils.convert(IteratorUtils.toList(iterator), SysConfig.class);
}
@ -89,7 +101,7 @@ public class SysConfigDataImpl implements ISysConfigData {
// TODO: 2023/5/26 抽成通用工具类方法
Page<TbSysConfig> all = alertConfigRepository.findAll(predicate, PageBuilder.toPageable(pageRequest));
Page<TbSysConfig> all = baseRepository.findAll(predicate, PageBuilder.toPageable(pageRequest));
return PageBuilder.toPaging(all, SysConfig.class);
@ -101,7 +113,7 @@ public class SysConfigDataImpl implements ISysConfigData {
Predicate predicate = PredicateBuilder.instance()
.and(StringUtils.isNotEmpty(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey()))
.build();
Iterator<TbSysConfig> iterator = alertConfigRepository.findAll(predicate).iterator();
Iterator<TbSysConfig> iterator = baseRepository.findAll(predicate).iterator();
return MapstructUtils.convert(IteratorUtils.toList(iterator), SysConfig.class);
}
@ -110,13 +122,13 @@ public class SysConfigDataImpl implements ISysConfigData {
Predicate predicate = PredicateBuilder.instance()
.and(StringUtils.isNotEmpty(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey()))
.build();
TbSysConfig tbSysConfig = alertConfigRepository.findOne(predicate).orElseThrow(() -> new BizException(ErrCode.DATA_NOT_EXIST));
TbSysConfig tbSysConfig = baseRepository.findOne(predicate).orElseThrow(() -> new BizException(ErrCode.DATA_NOT_EXIST));
return MapstructUtils.convert(tbSysConfig, SysConfig.class);
}
@Override
public SysConfig findByConfigKey(String configKey) {
TbSysConfig tbSysConfig = alertConfigRepository.findByConfigKey(configKey).orElseThrow(() ->
TbSysConfig tbSysConfig = baseRepository.findByConfigKey(configKey).orElseThrow(() ->
new BizException(ErrCode.DATA_NOT_EXIST));
return MapstructUtils.convert(tbSysConfig, SysConfig.class);
}