Commit f95e6674 authored by minminyan's avatar minminyan

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

parent d1870fa8
......@@ -45,6 +45,8 @@ public class InnerController {
private IAddressService addressService;
@Autowired
private IWechatService wechatService;
@Autowired
private IUserSpouseService userSpouseService;
@RequestMapping("/user/search/phoneNo")
......@@ -72,19 +74,19 @@ public class InnerController {
String phoneNo, Long registeredFrom, Long createdAt, Long updatedAt,
String password, String uuid) {
//参数验证
if(StringUtils.isBlank(phoneNo)){
if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("用户手机号不能为空.", null);
}
if(registeredFrom == null){
if (registeredFrom == null) {
registeredFrom = 0L;
}
if(StringUtils.isBlank(password)){
if (StringUtils.isBlank(password)) {
password = "";
}
if(StringUtils.isBlank(uuid)){
if (StringUtils.isBlank(uuid)) {
return JsonResult.buildErrorStateResult("用户uuid为空.", null);
}
if(createdAt == 0L || updatedAt == 0L){
if (createdAt == 0L || updatedAt == 0L) {
createdAt = System.currentTimeMillis();
updatedAt = System.currentTimeMillis();
}
......@@ -103,7 +105,7 @@ public class InnerController {
user.setPassword(password);
user = userService.saveUser(user);
UserRet userRet = null;
if(user != null){
if (user != null) {
userRet = UserRet.getUserRet(user);
}
return JsonResult.buildSuccessResult(null, userRet);
......@@ -111,6 +113,7 @@ public class InnerController {
/**
* 保存用户详细信息
*
* @param userId
* @param phoneNo
* @param name
......@@ -120,22 +123,22 @@ public class InnerController {
*/
@RequestMapping("/user_detail/save")
public JsonResult saveUserDetail(Long userId, String phoneNo, String name, String idNo,
String email, Long id){
String email, Long id) {
//参数验证
if(userId == null || userId == 0L){
if (userId == null || userId == 0L) {
return JsonResult.buildErrorStateResult("用户id为空.", null);
}
if(StringUtils.isBlank(phoneNo)){
if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("用户手机号为空.", null);
}
if(StringUtils.isBlank(name)){
if (StringUtils.isBlank(name)) {
return JsonResult.buildErrorStateResult("用户名为空.", null);
}
if(StringUtils.isBlank(idNo)){
if (StringUtils.isBlank(idNo)) {
return JsonResult.buildErrorStateResult("用户身份证为空.", null);
}
UserDetail userDetail = new UserDetail();
if(id != null && id > 0){
if (id != null && id > 0) {
userDetail.setId(id);
}
userDetail.setUserId(userId);
......@@ -154,47 +157,48 @@ public class InnerController {
}
userDetail.setEmail(email);
userDetail = userDetailService.saveUserDetail(userDetail);
if(userDetail != null){
if (userDetail != null) {
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
}
return JsonResult.buildErrorStateResult("",null);
return JsonResult.buildErrorStateResult("", null);
}
/**
* 根据用户id查询用户的详细信息
*
* @param userId
* @return
*/
@RequestMapping("/user_detail/search/userId")
public JsonResult findUserDetailByUserId(Long userId){
public JsonResult findUserDetailByUserId(Long userId) {
UserDetail userDetail = userDetailService.findByUserId(userId);
if(userDetail != null){
if (userDetail != null) {
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
}
return JsonResult.buildErrorStateResult("", null);
}
@RequestMapping("/user/search/userId")
public JsonResult findUserByUserId(Long userId){
public JsonResult findUserByUserId(Long userId) {
User user = userService.findById(userId);
if(user != null){
if (user != null) {
return JsonResult.buildSuccessResult(null, UserRet.getUserRet(user));
}
return JsonResult.buildErrorStateResult("", null);
}
@RequestMapping("/user_detail/search/phone")
public JsonResult findUserDetailByPhone(String phoneNo){
public JsonResult findUserDetailByPhone(String phoneNo) {
UserDetail userDetail = userDetailService.findByPhoneNo(phoneNo);
if(userDetail != null){
if (userDetail != null) {
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
}
return JsonResult.buildErrorStateResult("", null);
}
@RequestMapping("/user_detail/update/qq")
public JsonResult updateUserQQ(String qq, Long userId){
if(StringUtils.isEmpty(qq) || userId == null || userId == 0L){
public JsonResult updateUserQQ(String qq, Long userId) {
if (StringUtils.isEmpty(qq) || userId == null || userId == 0L) {
return JsonResult.buildErrorStateResult("参数校验失败,qq或用户id为空", null);
}
userDetailService.updateUserQQ(userId, qq);
......@@ -207,7 +211,7 @@ public class InnerController {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> contacts = contactService.findByUserId(userId);
if(null == contacts || contacts.size() == 0) {
if (null == contacts || contacts.size() == 0) {
return JsonResult.buildErrorStateResult(null, Collections.emptyList());
}
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(contacts));
......@@ -223,10 +227,11 @@ public class InnerController {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> userContact = contactService.findByUserId(userId);
if(userContact != null && userContact.size() >= 2) {
if (userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {});
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {
});
if (CollectionUtils.isEmpty(contacts)) {
return JsonResult.buildErrorStateResult(null, null);
}
......@@ -346,11 +351,11 @@ public class InnerController {
@RequestMapping("/user/query/openId")
public JsonResult queryOpenIdByUserId(Long userId) {
if(userId == null) {
if (userId == null) {
return JsonResult.buildErrorStateResult("userId不能为空", null);
}
WechatUserInfo wechatUserInfo = wechatService.queryOpenIdByUserId(userId);
if(wechatUserInfo == null) {
if (wechatUserInfo == null) {
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult("success", wechatUserInfo.getOpenId());
......@@ -358,14 +363,48 @@ public class InnerController {
@RequestMapping("/user/wechat/phone_no")
public JsonResult queryOpenIdByPhoneNo(String phoneNo) {
if(StringUtils.isBlank(phoneNo)) {
if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号错误", null);
}
if(!ValidationUtil.validatePhoneNo(phoneNo)) {
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号格式错误", null);
}
WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoByPhoneNo(phoneNo);
return JsonResult.buildSuccessResult(null, null == wechatUserInfo ? null : wechatUserInfo.getOpenId());
}
@RequestMapping("/user/spouse/save")
public JsonResult saveSpouse(Long userId, String spousePhone, String spouseName) {
if (userId == null || userId == 0) {
return JsonResult.buildErrorStateResult("用户不能为空", null);
}
if (!ValidationUtil.validatePhoneNo(spousePhone)) {
return JsonResult.buildErrorStateResult("手机号格式错误", null);
}
if (StringUtils.isBlank(spouseName)) {
return JsonResult.buildErrorStateResult("配偶姓名不能为空", null);
}
UserSpouse userSpouse = userSpouseService.findByUserId(userId);
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
if (userSpouse == null) {
userSpouse = new UserSpouse();
}
userSpouse.setSpouseName(spouseName);
userSpouse.setSpousePhone(spousePhone);
userSpouse.setUserId(userId);
userSpouse.setCreatedAt(timestamp);
userSpouse.setUpdateAt(timestamp);
userSpouse = userSpouseService.save(userSpouse);
return JsonResult.buildSuccessResult(null, userSpouse);
}
@RequestMapping("/user/spouse/findByUserId")
public JsonResult querySpouse(Long userId) {
if (userId == null || userId == 0) {
return JsonResult.buildErrorStateResult("用户不能为空", null);
}
UserSpouse userSpouse = userSpouseService.findByUserId(userId);
return JsonResult.buildSuccessResult(null, userSpouse);
}
}
\ No newline at end of file
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