Commit f95e6674 authored by minminyan's avatar minminyan

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

parent d1870fa8
...@@ -29,343 +29,382 @@ import java.util.List; ...@@ -29,343 +29,382 @@ import java.util.List;
@RequestMapping("/innerapi") @RequestMapping("/innerapi")
public class InnerController { public class InnerController {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(InnerController.class); private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(InnerController.class);
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired @Autowired
private IUserDetailService userDetailService; private IUserDetailService userDetailService;
@Autowired @Autowired
private IIdCardService idCardService; private IIdCardService idCardService;
@Autowired @Autowired
private IUserExtInfoService userExtInfoService; private IUserExtInfoService userExtInfoService;
@Autowired @Autowired
private IContactService contactService; private IContactService contactService;
@Autowired @Autowired
private IAddressService addressService; private IAddressService addressService;
@Autowired @Autowired
private IWechatService wechatService; private IWechatService wechatService;
@Autowired
private IUserSpouseService userSpouseService;
@RequestMapping("/user/search/phoneNo") @RequestMapping("/user/search/phoneNo")
public JsonResult findByPhoneNo(String phoneNo) { public JsonResult findByPhoneNo(String phoneNo) {
User user = userService.findByPhoneInDb(phoneNo); User user = userService.findByPhoneInDb(phoneNo);
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult("", null); return JsonResult.buildErrorStateResult("", null);
}
UserRet userRet = UserRet.getUserRet(user);
return JsonResult.buildSuccessResult("", userRet);
} }
UserRet userRet = UserRet.getUserRet(user);
return JsonResult.buildSuccessResult("", userRet);
}
@RequestMapping("/user/search/uuid") @RequestMapping("/user/search/uuid")
public JsonResult findByUuid(String uuid) { public JsonResult findByUuid(String uuid) {
User user = userService.findByUuidInDb(uuid); User user = userService.findByUuidInDb(uuid);
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult("", null); return JsonResult.buildErrorStateResult("", null);
}
UserRet userRet = UserRet.getUserRet(user);
return JsonResult.buildSuccessResult("", userRet);
} }
UserRet userRet = UserRet.getUserRet(user);
return JsonResult.buildSuccessResult("", userRet);
}
@RequestMapping("/user/save") @RequestMapping("/user/save")
public JsonResult saveUser( public JsonResult saveUser(
String phoneNo, Long registeredFrom, Long createdAt, Long updatedAt, String phoneNo, Long registeredFrom, Long createdAt, Long updatedAt,
String password, String uuid) { String password, String uuid) {
//参数验证 //参数验证
if(StringUtils.isBlank(phoneNo)){ if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("用户手机号不能为空.", null); return JsonResult.buildErrorStateResult("用户手机号不能为空.", null);
}
if(registeredFrom == null){
registeredFrom = 0L;
}
if(StringUtils.isBlank(password)){
password = "";
}
if(StringUtils.isBlank(uuid)){
return JsonResult.buildErrorStateResult("用户uuid为空.", null);
}
if(createdAt == 0L || updatedAt == 0L){
createdAt = System.currentTimeMillis();
updatedAt = System.currentTimeMillis();
}
User user = userService.findByPhoneWithCache(phoneNo);
if (user == null) {
user = new User();
}
if (org.apache.commons.lang.StringUtils.isEmpty(user.getUuid())) {
user.setUuid(uuid);
}
user.setPhoneNo(phoneNo);
user.setCreatedAt(new Timestamp(createdAt));
user.setUpdatedAt(new Timestamp(updatedAt));
user.setEnable(true);
user.setRegisteredFrom(registeredFrom);
user.setPassword(password);
user = userService.saveUser(user);
UserRet userRet = null;
if(user != null){
userRet = UserRet.getUserRet(user);
}
return JsonResult.buildSuccessResult(null, userRet);
} }
if (registeredFrom == null) {
registeredFrom = 0L;
}
if (StringUtils.isBlank(password)) {
password = "";
}
if (StringUtils.isBlank(uuid)) {
return JsonResult.buildErrorStateResult("用户uuid为空.", null);
}
if (createdAt == 0L || updatedAt == 0L) {
createdAt = System.currentTimeMillis();
updatedAt = System.currentTimeMillis();
}
User user = userService.findByPhoneWithCache(phoneNo);
if (user == null) {
user = new User();
}
if (org.apache.commons.lang.StringUtils.isEmpty(user.getUuid())) {
user.setUuid(uuid);
}
user.setPhoneNo(phoneNo);
user.setCreatedAt(new Timestamp(createdAt));
user.setUpdatedAt(new Timestamp(updatedAt));
user.setEnable(true);
user.setRegisteredFrom(registeredFrom);
user.setPassword(password);
user = userService.saveUser(user);
UserRet userRet = null;
if (user != null) {
userRet = UserRet.getUserRet(user);
}
return JsonResult.buildSuccessResult(null, userRet);
}
/** /**
* 保存用户详细信息 * 保存用户详细信息
* @param userId *
* @param phoneNo * @param userId
* @param name * @param phoneNo
* @param idNo * @param name
* @param email * @param idNo
* @return * @param email
*/ * @return
@RequestMapping("/user_detail/save") */
public JsonResult saveUserDetail(Long userId, String phoneNo, String name, String idNo, @RequestMapping("/user_detail/save")
String email, Long id){ public JsonResult saveUserDetail(Long userId, String phoneNo, String name, String idNo,
//参数验证 String email, Long id) {
if(userId == null || userId == 0L){ //参数验证
return JsonResult.buildErrorStateResult("用户id为空.", null); if (userId == null || userId == 0L) {
} return JsonResult.buildErrorStateResult("用户id为空.", null);
if(StringUtils.isBlank(phoneNo)){ }
return JsonResult.buildErrorStateResult("用户手机号为空.", null); if (StringUtils.isBlank(phoneNo)) {
} return JsonResult.buildErrorStateResult("用户手机号为空.", null);
if(StringUtils.isBlank(name)){ }
return JsonResult.buildErrorStateResult("用户名为空.", null); if (StringUtils.isBlank(name)) {
} return JsonResult.buildErrorStateResult("用户名为空.", null);
if(StringUtils.isBlank(idNo)){ }
return JsonResult.buildErrorStateResult("用户身份证为空.", null); if (StringUtils.isBlank(idNo)) {
} return JsonResult.buildErrorStateResult("用户身份证为空.", null);
UserDetail userDetail = new UserDetail();
if(id != null && id > 0){
userDetail.setId(id);
}
userDetail.setUserId(userId);
userDetail.setName(name);
userDetail.setPhoneNo(phoneNo);
userDetail.setIdNo(idNo);
Timestamp time = new Timestamp(System.currentTimeMillis());
userDetail.setCreatedAt(time);
userDetail.setUpdatedAt(time);
userDetail.setIdType(IdType.ID_CARD);
try {
userDetail.setGender(idCardService.getIdCardInfo(idNo).getGender());
} catch (ParseException e) {
LOGGER.error("根据身份证获取性别出错,错误信息:" + e);
return JsonResult.buildErrorStateResult(null, null);
}
userDetail.setEmail(email);
userDetail = userDetailService.saveUserDetail(userDetail);
if(userDetail != null){
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
}
return JsonResult.buildErrorStateResult("",null);
} }
UserDetail userDetail = new UserDetail();
if (id != null && id > 0) {
userDetail.setId(id);
}
userDetail.setUserId(userId);
userDetail.setName(name);
userDetail.setPhoneNo(phoneNo);
userDetail.setIdNo(idNo);
Timestamp time = new Timestamp(System.currentTimeMillis());
userDetail.setCreatedAt(time);
userDetail.setUpdatedAt(time);
userDetail.setIdType(IdType.ID_CARD);
try {
userDetail.setGender(idCardService.getIdCardInfo(idNo).getGender());
} catch (ParseException e) {
LOGGER.error("根据身份证获取性别出错,错误信息:" + e);
return JsonResult.buildErrorStateResult(null, null);
}
userDetail.setEmail(email);
userDetail = userDetailService.saveUserDetail(userDetail);
if (userDetail != null) {
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
}
return JsonResult.buildErrorStateResult("", null);
}
/** /**
* 根据用户id查询用户的详细信息 * 根据用户id查询用户的详细信息
* @param userId *
* @return * @param userId
*/ * @return
@RequestMapping("/user_detail/search/userId") */
public JsonResult findUserDetailByUserId(Long userId){ @RequestMapping("/user_detail/search/userId")
UserDetail userDetail = userDetailService.findByUserId(userId); public JsonResult findUserDetailByUserId(Long userId) {
if(userDetail != null){ UserDetail userDetail = userDetailService.findByUserId(userId);
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail)); if (userDetail != null) {
} return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
return JsonResult.buildErrorStateResult("", null);
} }
return JsonResult.buildErrorStateResult("", null);
}
@RequestMapping("/user/search/userId") @RequestMapping("/user/search/userId")
public JsonResult findUserByUserId(Long userId){ public JsonResult findUserByUserId(Long userId) {
User user = userService.findById(userId); User user = userService.findById(userId);
if(user != null){ if (user != null) {
return JsonResult.buildSuccessResult(null, UserRet.getUserRet(user)); return JsonResult.buildSuccessResult(null, UserRet.getUserRet(user));
}
return JsonResult.buildErrorStateResult("", null);
} }
return JsonResult.buildErrorStateResult("", null);
}
@RequestMapping("/user_detail/search/phone") @RequestMapping("/user_detail/search/phone")
public JsonResult findUserDetailByPhone(String phoneNo){ public JsonResult findUserDetailByPhone(String phoneNo) {
UserDetail userDetail = userDetailService.findByPhoneNo(phoneNo); UserDetail userDetail = userDetailService.findByPhoneNo(phoneNo);
if(userDetail != null){ if (userDetail != null) {
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail)); return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
}
return JsonResult.buildErrorStateResult("", null);
} }
return JsonResult.buildErrorStateResult("", null);
}
@RequestMapping("/user_detail/update/qq") @RequestMapping("/user_detail/update/qq")
public JsonResult updateUserQQ(String qq, Long userId){ public JsonResult updateUserQQ(String qq, Long userId) {
if(StringUtils.isEmpty(qq) || userId == null || userId == 0L){ if (StringUtils.isEmpty(qq) || userId == null || userId == 0L) {
return JsonResult.buildErrorStateResult("参数校验失败,qq或用户id为空", null); return JsonResult.buildErrorStateResult("参数校验失败,qq或用户id为空", null);
}
userDetailService.updateUserQQ(userId, qq);
return JsonResult.buildSuccessResult(null, null);
} }
userDetailService.updateUserQQ(userId, qq);
return JsonResult.buildSuccessResult(null, null);
}
@RequestMapping("/contact/search/user_id") @RequestMapping("/contact/search/user_id")
public JsonResult findContactsByUserId(Long userId) { public JsonResult findContactsByUserId(Long userId) {
if (null == userId) { if (null == userId) {
return JsonResult.buildErrorStateResult(null, null); return JsonResult.buildErrorStateResult(null, null);
} }
List<Contact> contacts = contactService.findByUserId(userId); 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.buildErrorStateResult(null, Collections.emptyList());
} }
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(contacts)); return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(contacts));
}
@RequestMapping("/contact/save/contacts")
public JsonResult save2Contact(Long userId, @RequestParam(value = "contacts") String contactsStr) {
LOGGER.info("保存用户联系人:userId:{}, contacts:" + contactsStr);
if (StringUtils.isEmpty(contactsStr)) {
return JsonResult.buildErrorStateResult(null, null);
}
if (userId == null) {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> userContact = contactService.findByUserId(userId);
if (userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {
});
if (CollectionUtils.isEmpty(contacts)) {
return JsonResult.buildErrorStateResult(null, null);
} }
Timestamp now = new Timestamp(System.currentTimeMillis());
for (Contact c : contacts) {
c.setId(null);
c.setUserId(userId);
c.setRelation(c.getRelation() == null ? Relation.OTHER : c.getRelation());
c.setCreatedAt(now);
c.setUpdateAt(now);
}
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(result));
}
@RequestMapping("/contact/save/contacts") @RequestMapping("/address/search/user_id")
public JsonResult save2Contact(Long userId, @RequestParam(value = "contacts") String contactsStr) { public JsonResult findAddressByUserId(Long userId) {
LOGGER.info("保存用户联系人:userId:{}, contacts:" + contactsStr); if (userId == null) {
if (StringUtils.isEmpty(contactsStr)) { return JsonResult.buildErrorStateResult(null, null);
return JsonResult.buildErrorStateResult(null, null); }
} Address address = addressService.findByUserId(userId);
if (userId == null) { if (address == null) {
return JsonResult.buildErrorStateResult(null, null); return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> userContact = contactService.findByUserId(userId);
if(userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {});
if (CollectionUtils.isEmpty(contacts)) {
return JsonResult.buildErrorStateResult(null, null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
for (Contact c : contacts) {
c.setId(null);
c.setUserId(userId);
c.setRelation(c.getRelation() == null ? Relation.OTHER : c.getRelation());
c.setCreatedAt(now);
c.setUpdateAt(now);
}
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(result));
} }
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(address));
}
@RequestMapping("/address/search/user_id") @RequestMapping("/address/save")
public JsonResult findAddressByUserId(Long userId) { public JsonResult saveAddress(
if (userId == null) { Long userId, Long provinceCode, Long cityCode, String city,
return JsonResult.buildErrorStateResult(null, null); Long districtCode, String district, String address, String province) {
} LOGGER.info("保存地址详情:city:{},province:{}" + city, province);
Address address = addressService.findByUserId(userId); if (userId == null || provinceCode == null || cityCode == null) {
if (address == null) { return JsonResult.buildErrorStateResult(null, null);
return JsonResult.buildErrorStateResult(null, null); }
} Address addressObj = addressService.findByUserId(userId);
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(address)); if (addressObj == null) {
addressObj = new Address();
Timestamp now = new Timestamp(System.currentTimeMillis());
addressObj.setCreatedAt(now);
addressObj.setUpdateAt(now);
} }
addressObj.setUserId(userId);
addressObj.setProvinceCode(provinceCode);
addressObj.setCityCode(cityCode);
addressObj.setCity(city);
addressObj.setDistrictCode(districtCode);
addressObj.setDistrict(district);
addressObj.setAddress(address);
addressObj.setProvince(province);
addressObj = addressService.save(addressObj);
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(addressObj));
}
@RequestMapping("/address/save")
public JsonResult saveAddress( @RequestMapping("/user_ext_info/update")
Long userId, Long provinceCode, Long cityCode, String city, public JsonResult updateMarryStatus(
Long districtCode, String district, String address, String province) { Long userId, IncomeEnum incomeEnum, IncomeRangeEnum incomeRangeEnum,
LOGGER.info("保存地址详情:city:{},province:{}" + city, province); OccupationEnum occupationEnum, EducationEnum educationEnum, Boolean hasCar,
if (userId == null || provinceCode == null || cityCode == null) { Boolean hasSocialSecurity, Boolean hasHouse, Boolean hasCreditCard, MaritalStatus maritalStatus) {
return JsonResult.buildErrorStateResult(null, null); if (null == userId) {
} return JsonResult.buildErrorStateResult("用户ID不能为空", null);
Address addressObj = addressService.findByUserId(userId); }
if (addressObj == null) { UserExtInfo info = userExtInfoService.findByUserId(userId);
addressObj = new Address(); if (info == null) {
Timestamp now = new Timestamp(System.currentTimeMillis()); Timestamp now = new Timestamp(System.currentTimeMillis());
addressObj.setCreatedAt(now); info = new UserExtInfo();
addressObj.setUpdateAt(now); info.setUserId(userId);
} info.setCreatedAt(now);
addressObj.setUserId(userId); info.setUpdateAt(now);
addressObj.setProvinceCode(provinceCode); }
addressObj.setCityCode(cityCode); if (incomeEnum != null) {
addressObj.setCity(city); info.setIncomeEnum(incomeEnum);
addressObj.setDistrictCode(districtCode); }
addressObj.setDistrict(district); if (incomeRangeEnum != null) {
addressObj.setAddress(address); info.setIncomeRangeEnum(incomeRangeEnum);
addressObj.setProvince(province); }
addressObj = addressService.save(addressObj); if (occupationEnum != null) {
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(addressObj)); info.setOccupationEnum(occupationEnum);
}
if (educationEnum != null) {
info.setEducationEnum(educationEnum);
}
if (hasCar != null) {
info.setHasCar(hasCar);
} }
if (hasSocialSecurity != null) {
info.setHasCreditCard(hasCreditCard);
}
if (hasHouse != null) {
info.setHasHouse(hasHouse);
}
if (maritalStatus != null) {
info.setMarryStatus(maritalStatus);
}
info = userExtInfoService.save(info);
return JsonResult.buildSuccessResult(null, UserExtInfoRet.getUserExtInfoRet(info));
}
@RequestMapping("/user_detail/search_list")
public JsonResult searchUserDetailList(String name, String phoneNo, String idNo) {
List<UserDetail> userDetails = userDetailService.searchUserDetailList(name, phoneNo, idNo);
return JsonResult.buildSuccessResult("success", userDetails);
}
@RequestMapping("/user_ext_info/update") @RequestMapping("/user_ext_info/search/user_id")
public JsonResult updateMarryStatus( public JsonResult searchUserExtInfoByUserId(Long userId) {
Long userId, IncomeEnum incomeEnum, IncomeRangeEnum incomeRangeEnum, if (userId == null) {
OccupationEnum occupationEnum, EducationEnum educationEnum, Boolean hasCar, return JsonResult.buildErrorStateResult("userId不能为空", null);
Boolean hasSocialSecurity, Boolean hasHouse, Boolean hasCreditCard, MaritalStatus maritalStatus) {
if (null == userId) {
return JsonResult.buildErrorStateResult("用户ID不能为空", null);
}
UserExtInfo info = userExtInfoService.findByUserId(userId);
if (info == null) {
Timestamp now = new Timestamp(System.currentTimeMillis());
info = new UserExtInfo();
info.setUserId(userId);
info.setCreatedAt(now);
info.setUpdateAt(now);
}
if (incomeEnum != null) {
info.setIncomeEnum(incomeEnum);
}
if (incomeRangeEnum != null) {
info.setIncomeRangeEnum(incomeRangeEnum);
}
if (occupationEnum != null) {
info.setOccupationEnum(occupationEnum);
}
if (educationEnum != null) {
info.setEducationEnum(educationEnum);
}
if (hasCar != null) {
info.setHasCar(hasCar);
}
if (hasSocialSecurity != null) {
info.setHasCreditCard(hasCreditCard);
}
if (hasHouse != null) {
info.setHasHouse(hasHouse);
}
if (maritalStatus != null) {
info.setMarryStatus(maritalStatus);
}
info = userExtInfoService.save(info);
return JsonResult.buildSuccessResult(null, UserExtInfoRet.getUserExtInfoRet(info));
} }
UserExtInfo userExtInfo = userExtInfoService.findByUserId(userId);
if (userExtInfo == null) {
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult("success", UserExtInfoRet.getUserExtInfoRet(userExtInfo));
}
@RequestMapping("/user_detail/search_list") @RequestMapping("/user/query/openId")
public JsonResult searchUserDetailList(String name, String phoneNo, String idNo) { public JsonResult queryOpenIdByUserId(Long userId) {
List<UserDetail> userDetails = userDetailService.searchUserDetailList(name, phoneNo, idNo); if (userId == null) {
return JsonResult.buildSuccessResult("success", userDetails); return JsonResult.buildErrorStateResult("userId不能为空", null);
}
WechatUserInfo wechatUserInfo = wechatService.queryOpenIdByUserId(userId);
if (wechatUserInfo == null) {
return JsonResult.buildErrorStateResult(null, null);
} }
return JsonResult.buildSuccessResult("success", wechatUserInfo.getOpenId());
}
@RequestMapping("/user_ext_info/search/user_id") @RequestMapping("/user/wechat/phone_no")
public JsonResult searchUserExtInfoByUserId(Long userId) { public JsonResult queryOpenIdByPhoneNo(String phoneNo) {
if (userId == null) { if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("userId不能为空", null); return JsonResult.buildErrorStateResult("手机号错误", null);
}
UserExtInfo userExtInfo = userExtInfoService.findByUserId(userId);
if (userExtInfo == null) {
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult("success", UserExtInfoRet.getUserExtInfoRet(userExtInfo));
} }
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号格式错误", null);
}
WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoByPhoneNo(phoneNo);
return JsonResult.buildSuccessResult(null, null == wechatUserInfo ? null : wechatUserInfo.getOpenId());
}
@RequestMapping("/user/query/openId") @RequestMapping("/user/spouse/save")
public JsonResult queryOpenIdByUserId(Long userId) { public JsonResult saveSpouse(Long userId, String spousePhone, String spouseName) {
if(userId == null) { if (userId == null || userId == 0) {
return JsonResult.buildErrorStateResult("userId不能为空", null); return JsonResult.buildErrorStateResult("用户不能为空", null);
} }
WechatUserInfo wechatUserInfo = wechatService.queryOpenIdByUserId(userId); if (!ValidationUtil.validatePhoneNo(spousePhone)) {
if(wechatUserInfo == null) { return JsonResult.buildErrorStateResult("手机号格式错误", null);
return JsonResult.buildErrorStateResult(null, null); }
} if (StringUtils.isBlank(spouseName)) {
return JsonResult.buildSuccessResult("success", wechatUserInfo.getOpenId()); 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/wechat/phone_no") @RequestMapping("/user/spouse/findByUserId")
public JsonResult queryOpenIdByPhoneNo(String phoneNo) { public JsonResult querySpouse(Long userId) {
if(StringUtils.isBlank(phoneNo)) { if (userId == null || userId == 0) {
return JsonResult.buildErrorStateResult("手机号错误", null); return JsonResult.buildErrorStateResult("用户不能为空", null);
}
if(!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号格式错误", null);
}
WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoByPhoneNo(phoneNo);
return JsonResult.buildSuccessResult(null, null == wechatUserInfo ? null : wechatUserInfo.getOpenId());
} }
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