补充家庭空间数据库操作
parent
a7fd715409
commit
15ee8a068f
|
@ -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))
|
||||
);
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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<>();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue