Commit 81f28e1c authored by wudi's avatar wudi

Merge branch 'master' into wechat-pay

parents 1229d1b9 86bb1bac
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.entity.enumerate.MaritalStatus;
import lombok.*;
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
@NoArgsConstructor
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;
@Column(name = "status")
private MaritalStatus status;
public UserSpouse(Long userId) {
this.userId = userId;
}
}
package cn.quantgroup.xyqb.model;
import cn.quantgroup.xyqb.entity.UserSpouse;
import cn.quantgroup.xyqb.entity.enumerate.MaritalStatus;
import lombok.Data;
/**
* Created by 11 on 2017/4/19.
*/
@Data
public class UserSpouseRet {
private Long userId;
private String spousePhone;
private String spouseName;
private Long createdAt;
private Long updateAt;
private MaritalStatus status;
public static UserSpouseRet getUserSpouseRet(UserSpouse userSpouse) {
if (userSpouse == null) {
return null;
}
UserSpouseRet ret = new UserSpouseRet();
ret.setUserId(userSpouse.getUserId());
ret.setSpouseName(userSpouse.getSpouseName());
ret.setSpousePhone(userSpouse.getSpousePhone());
if (userSpouse.getUpdateAt() != null) {
ret.setUpdateAt(userSpouse.getUpdateAt().getTime());
}
if (userSpouse.getCreatedAt() != null) {
ret.setCreatedAt(userSpouse.getCreatedAt().getTime());
}
ret.setStatus(userSpouse.getStatus());
return ret;
}
}
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