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

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

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