Commit f95e6674 authored by minminyan's avatar minminyan

添加保存与查询配偶信息的接口

parent d1870fa8
package cn.quantgroup.xyqb.entity;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
@Data
@Entity
@Table(name = "user_spouse", uniqueConstraints = @UniqueConstraint(columnNames = "user_id"))
@Getter
@Setter
@ToString
public class UserSpouse implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "spouse_phone")
private String spousePhone;
@Column(name = "spouse_name")
private String spouseName;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updateAt;
}
package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.UserSpouse;
import org.springframework.data.jpa.repository.JpaRepository;
public interface IUserSpouseRepository extends JpaRepository<UserSpouse, Long> {
UserSpouse findByUserId(Long userId);
}
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.UserSpouse;
public interface IUserSpouseService {
UserSpouse findByUserId(Long userId);
UserSpouse save(UserSpouse userSpouse);
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.UserSpouse;
import cn.quantgroup.xyqb.repository.IUserSpouseRepository;
import cn.quantgroup.xyqb.service.user.IUserSpouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
public class UserSpouseServiceImpl implements IUserSpouseService {
@Autowired
private IUserSpouseRepository userSpouseRepository;
@Override
@Cacheable(value = "userSpouseCache", key = "'spouse' + #userId", unless = "#result == null", cacheManager = "cacheManager")
public UserSpouse findByUserId(Long userId) {
return userSpouseRepository.findByUserId(userId);
}
@Override
@CacheEvict(value = "userSpouseCache", key = "'spouse' + #userSpouse.userId", cacheManager = "cacheManager")
public UserSpouse save(UserSpouse userSpouse) {
return userSpouseRepository.save(userSpouse);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment