补充家庭空间数据库操作

V0.5.x
xiwa 2022-11-06 23:26:27 +08:00
parent a7fd715409
commit 15ee8a068f
5 changed files with 130 additions and 10 deletions

View File

@ -45,6 +45,7 @@ public class CacheConfig {
Constants.CACHE_OAUTH_CLIENT, config,
Constants.CACHE_CATEGORY, config,
Constants.CACHE_THING_MODEL, config,
Constants.CACHE_SPACE, config,
//统计缓存5分钟
Constants.CACHE_DEVICE_STATS, config.entryTtl(Duration.ofMinutes(5))
);

View File

@ -0,0 +1,37 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.data.dao;
import cc.iotkit.data.model.TbHome;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface HomeRepository extends JpaRepository<TbHome, String> {
TbHome findByUidAndCurrent(String uid, boolean current);
TbHome findByUidAndId(String uid, String id);
List<TbHome> findByUid(String uid);
Page<TbHome> findByUid(String uid, Pageable pageable);
long countByUid(String uid);
void deleteById(String s);
long count();
List<TbHome> findAll();
}

View File

@ -0,0 +1,22 @@
package cc.iotkit.data.model;
import cc.iotkit.model.space.Home;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.stream.Collectors;
@Mapper
public interface HomeMapper {
HomeMapper M = Mappers.getMapper(HomeMapper.class);
Home toDto(TbHome vo);
TbHome toVo(Home dto);
static List<Home> toDto(List<TbHome> homes) {
return homes.stream().map(M::toDto).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,47 @@
package cc.iotkit.data.model;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "home")
public class TbHome {
@Id
private String id;
/**
*
*/
private String name;
/**
*
*/
private String address;
/**
* id
*/
private String uid;
/**
*
*/
private Integer spaceNum;
/**
*
*/
private Integer deviceNum;
/**
* 使
*/
private Boolean current;
}

View File

@ -1,29 +1,38 @@
package cc.iotkit.data.service;
import cc.iotkit.data.IHomeData;
import cc.iotkit.data.dao.HomeRepository;
import cc.iotkit.data.model.HomeMapper;
import cc.iotkit.model.Paging;
import cc.iotkit.model.space.Home;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.UUID;
@Primary
@Service
public class HomeDataImpl implements IHomeData {
@Autowired
private HomeRepository homeRepository;
@Override
public Home findByUidAndCurrent(String uid, boolean current) {
return null;
return HomeMapper.M.toDto(homeRepository.findByUidAndCurrent(uid, current));
}
@Override
public Home findByUidAndId(String uid, String id) {
return null;
return HomeMapper.M.toDto(homeRepository.findByUidAndId(uid, id));
}
@Override
public List<Home> findByUid(String uid) {
return null;
return HomeMapper.toDto(homeRepository.findByUid(uid));
}
@Override
@ -38,36 +47,40 @@ public class HomeDataImpl implements IHomeData {
@Override
public Home findById(String s) {
return null;
return HomeMapper.M.toDto(homeRepository.findById(s).orElse(null));
}
@Override
public Home save(Home data) {
return null;
if (StringUtils.isBlank(data.getId())) {
data.setId(UUID.randomUUID().toString());
}
homeRepository.save(HomeMapper.M.toVo(data));
return data;
}
@Override
public Home add(Home data) {
return null;
return save(data);
}
@Override
public void deleteById(String s) {
homeRepository.deleteById(s);
}
@Override
public long count() {
return 0;
return homeRepository.count();
}
@Override
public List<Home> findAll() {
return null;
return HomeMapper.toDto(homeRepository.findAll());
}
@Override
public Paging<Home> findAll(int page, int size) {
return null;
return new Paging<>();
}
}