Commit f5ae5134 authored by 朱劲松​'s avatar 朱劲松​

feature: 保存用户信息的扩展 * 提供用户的最少字段即可完成保存

     * 地址信息,联系人信息等需要完整提供或者完全不提供,不提供则忽略
parent 435fc48c
...@@ -1025,28 +1025,44 @@ public class InnerController implements IBaseController { ...@@ -1025,28 +1025,44 @@ public class InnerController implements IBaseController {
if (!isIdCard) { if (!isIdCard) {
return JsonResult.buildErrorStateResult("用户身份证号异常.", null); return JsonResult.buildErrorStateResult("用户身份证号异常.", null);
} }
if (!NumberUtils.isDigits(provinceCode)) {
return JsonResult.buildErrorStateResult("省份编号异常.", null);
} Address addressObj = null;
if (StringUtils.isBlank(province)) { //地址信息,同时存在provinceCode和address时才校验地址信息
return JsonResult.buildErrorStateResult("省份异常.", null); if (StringUtils.isNotEmpty(provinceCode) && StringUtils.isNotEmpty(address)) {
} if (!NumberUtils.isDigits(provinceCode)) {
if (!NumberUtils.isDigits(cityCode)) { return JsonResult.buildErrorStateResult("省份编号异常.", null);
return JsonResult.buildErrorStateResult("城市编号异常.", null); }
} if (StringUtils.isBlank(province)) {
if (StringUtils.isBlank(city)) { return JsonResult.buildErrorStateResult("省份异常.", null);
return JsonResult.buildErrorStateResult("城市异常.", null); }
} if (!NumberUtils.isDigits(cityCode)) {
if (!NumberUtils.isDigits(districtCode)) { return JsonResult.buildErrorStateResult("城市编号异常.", null);
return JsonResult.buildErrorStateResult("区县编号异常.", null); }
} if (StringUtils.isBlank(city)) {
if (StringUtils.isBlank(district)) { return JsonResult.buildErrorStateResult("城市异常.", null);
return JsonResult.buildErrorStateResult("区县异常.", null); }
} if (!NumberUtils.isDigits(districtCode)) {
if (StringUtils.isBlank(address)) { return JsonResult.buildErrorStateResult("区县编号异常.", null);
return JsonResult.buildErrorStateResult("详细地址异常.", null); }
if (StringUtils.isBlank(district)) {
return JsonResult.buildErrorStateResult("区县异常.", null);
}
if (StringUtils.isBlank(address)) {
return JsonResult.buildErrorStateResult("详细地址异常.", null);
}
addressObj = new Address();
addressObj.setProvinceCode(Long.valueOf(provinceCode));
addressObj.setProvince(province);
addressObj.setCityCode(Long.valueOf(cityCode));
addressObj.setCity(city);
addressObj.setDistrictCode(Long.valueOf(districtCode));
addressObj.setDistrict(district);
addressObj.setAddress(address);
} }
channelId = MoreObjects.firstNonNull(channelId, "-1"); channelId = MoreObjects.firstNonNull(channelId, "-1");
// 验证用户是否已存在 // 验证用户是否已存在
User user = userService.findByPhoneInDb(phoneNo); User user = userService.findByPhoneInDb(phoneNo);
...@@ -1054,7 +1070,7 @@ public class InnerController implements IBaseController { ...@@ -1054,7 +1070,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("用户已存在,手机号被占用", null); return JsonResult.buildErrorStateResult("用户已存在,手机号被占用", null);
} }
user = userRegisterService.register(Long.valueOf(registeredFrom), Long.valueOf(channelId), phoneNo, name, idNo, provinceCode, province, cityCode, city, districtCode, district, address, contacts, btRegisterChannelId); user = userRegisterService.register(Long.valueOf(registeredFrom), Long.valueOf(channelId), phoneNo, name, idNo, addressObj, contacts, btRegisterChannelId);
UserRet userRet = new UserRet(user); UserRet userRet = new UserRet(user);
return JsonResult.buildSuccessResult(null, userRet); return JsonResult.buildSuccessResult(null, userRet);
......
package cn.quantgroup.xyqb.service.register; package cn.quantgroup.xyqb.service.register;
import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.UserRegisterParam; import cn.quantgroup.xyqb.model.UserRegisterParam;
...@@ -84,22 +85,11 @@ public interface IUserRegisterService { ...@@ -84,22 +85,11 @@ public interface IUserRegisterService {
* 替换InnerController.saveMulti里的userService.registerAndReturn * 替换InnerController.saveMulti里的userService.registerAndReturn
* /innserapi/user/save_multi * /innserapi/user/save_multi
* *
* @param registeredFrom * @version 0.2
* @param channelId * @author jinsong.zhu 2018年05月16日14:22:13
* @param phoneNo * 处理对address和contact的非必要兼容
* @param name
* @param idNo
* @param provinceCode
* @param province
* @param cityCode
* @param city
* @param districtCode
* @param district
* @param address
* @param contacts
* @return
*/ */
User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo, String provinceCode, String province, String cityCode, String city, String districtCode, String district, String address, String contacts, Long btRegisterChannelId); User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo, Address addressObj, String contacts, Long btRegisterChannelId);
/** /**
* 替换MotanUserServiceImpl.appLoginAndFetchLoginInfo和MotanUserServiceImpl.appLogin里的register * 替换MotanUserServiceImpl.appLoginAndFetchLoginInfo和MotanUserServiceImpl.appLogin里的register
...@@ -112,4 +102,5 @@ public interface IUserRegisterService { ...@@ -112,4 +102,5 @@ public interface IUserRegisterService {
* @return * @return
*/ */
User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId); User register(Long registerFrom, String phoneNo, String idNo, String name, Long channelId);
} }
...@@ -29,12 +29,15 @@ public class AddressUserRegisterHandler extends AbstractUserRegisterHandler { ...@@ -29,12 +29,15 @@ public class AddressUserRegisterHandler extends AbstractUserRegisterHandler {
@Override @Override
public User handleRegister(UserRegisterParam userRegisterParam) { public User handleRegister(UserRegisterParam userRegisterParam) {
Address address = userRegisterParam.getAddress(); Address address = userRegisterParam.getAddress();
User user = userRegisterParam.getUser(); if (address != null) {
address.setUserId(user.getId()); User user = userRegisterParam.getUser();
Timestamp currentTime = new Timestamp(System.currentTimeMillis()); address.setUserId(user.getId());
address.setCreatedAt(currentTime); Timestamp currentTime = new Timestamp(System.currentTimeMillis());
address.setUpdateAt(currentTime); address.setCreatedAt(currentTime);
addressRepository.save(address); address.setUpdateAt(currentTime);
addressRepository.save(address);
}
if (successor != null) { if (successor != null) {
return successor.handleRegister(userRegisterParam); return successor.handleRegister(userRegisterParam);
} }
......
...@@ -79,15 +79,7 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService { ...@@ -79,15 +79,7 @@ public class UserRegisterServiceImpl extends AbstractUserRegisterService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo, String provinceCode, String province, String cityCode, String city, String districtCode, String district, String address, String contacts, Long btRegisterChannelId) { public User register(Long registeredFrom, Long channelId, String phoneNo, String name, String idNo, Address addressObj, String contacts, Long btRegisterChannelId) {
Address addressObj = new Address();
addressObj.setProvinceCode(Long.valueOf(provinceCode));
addressObj.setProvince(province);
addressObj.setCityCode(Long.valueOf(cityCode));
addressObj.setCity(city);
addressObj.setDistrictCode(Long.valueOf(districtCode));
addressObj.setDistrict(district);
addressObj.setAddress(address);
UserRegisterParam userRegisterParam = UserRegisterParam.builder() UserRegisterParam userRegisterParam = UserRegisterParam.builder()
.registerFrom(registeredFrom).phoneNo(phoneNo).idNo(idNo).name(name) .registerFrom(registeredFrom).phoneNo(phoneNo).idNo(idNo).name(name)
.channelId(channelId) .channelId(channelId)
......
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