Commit 6a999e74 authored by chenzhao's avatar chenzhao

农户登录注册修改

parent 04f4304f
......@@ -2,6 +2,8 @@ package com.yeejoin.amos.boot.module.hygf.api.util;
import org.springframework.beans.BeanUtils;
import java.lang.reflect.Field;
public class BeanDtoUtils {
......@@ -34,4 +36,37 @@ public class BeanDtoUtils {
return null;
}
}
public static <S, T> void copyPropertiesNonNull(S source, T target) {
if (source == null || target == null) {
throw new IllegalArgumentException("Source and target cannot be null");
}
// 使用反射获取源对象的所有属性
Field[] sourceFields = source.getClass().getDeclaredFields();
for (Field sourceField : sourceFields) {
if (sourceField.getName().equals("serialVersionUID")){
continue;
}
sourceField.setAccessible(true);
// 获取目标对象中对应的属性
try {
Field targetField = target.getClass().getDeclaredField(sourceField.getName());
targetField.setAccessible(true);
// 获取源对象的属性值
Object sourceValue = sourceField.get(source);
// 如果源对象的属性值不是 null,则复制到目标对象
if (sourceValue != null ) {
targetField.set(target, sourceValue);
}
} catch (NoSuchFieldException e) {
// 如果目标对象没有对应的属性,则忽略
} catch (IllegalAccessException e) {
// 如果访问属性时发生异常,则抛出运行时异常
throw new RuntimeException(e);
}
}
}
}
......@@ -6,12 +6,15 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.hygf.api.dto.MobileLoginParamDto;
import com.yeejoin.amos.boot.module.hygf.api.dto.PeasantHouseholdDto;
import com.yeejoin.amos.boot.module.hygf.api.dto.PeasantHouseholdWxDto;
import com.yeejoin.amos.boot.module.hygf.api.entity.PeasantHousehold;
import com.yeejoin.amos.boot.module.hygf.api.service.IWxService;
import com.yeejoin.amos.boot.module.hygf.api.util.BeanDtoUtils;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.HouseholdContractServiceImpl;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.PeasantHouseholdServiceImpl;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.SurveyInformationServiceImpl;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
......@@ -21,9 +24,11 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
......@@ -107,52 +112,87 @@ public class PeasantHouseholdWxController extends BaseController {
return ResponseHelper.buildResponse(peasantHouseholdServiceImpl.wxUserLogin(mobileLoginParam));
}
@TycloudOperation (ApiLevel = UserType.AGENCY, needAuth = false)
@RequestMapping (value = "/getRegisterPhone", method = RequestMethod.POST)
@ApiOperation (httpMethod = "POST", value = "获取手机号及回填信息", notes = "获取手机号及回填信息")
public ResponseModel<Map<String,Object>> getRegisterPhone(@ApiParam @RequestBody MobileLoginParamDto mobileLoginParam) {
log.info("微信授权注册入参 => {}", mobileLoginParam);
if (StringUtils.isBlank(mobileLoginParam.getAmosUserId())) {
// 扫码的userId为空, 则取默认值
mobileLoginParam.setAmosUserId(defaultUserId);
}
return ResponseHelper.buildResponse(peasantHouseholdServiceImpl.getRegisterPhone(mobileLoginParam));
}
@TycloudOperation (ApiLevel = UserType.AGENCY, needAuth = false)
@RequestMapping (value = "/register", method = RequestMethod.POST)
@ApiOperation (httpMethod = "POST", value = "微信农户注册", notes = "微信农户注册")
public ResponseModel<PeasantHouseholdDto> wxUserRegister(@ApiParam @RequestBody MobileLoginParamDto mobileLoginParam) {
log.info("微信农户注册, 入参 => {}", mobileLoginParam);
PeasantHouseholdDto model = mobileLoginParam.getPeasantHouseholdDto();
validatedPeasantHouseholdDto(model);
AgencyUserModel userInfo = getUserInfo();
model.setAmosUserId(userInfo.getUserId());// 绑定平台userId
model.setPeasantHouseholdNo(peasantHouseholdServiceImpl.getPeasantHouseholdNo(model.getRegionalCompaniesSeq()));
model.setIsCertified(1);// 这里就实名认证
model.setSurveyOrNot(0);
model.setReview(0);
JSONArray regionName = getRegionName();
List<RegionModel> list = JSONArray.parseArray(regionName.toJSONString(), RegionModel.class);
// 处理项目地址
String area = "";
if (model.getProjectAddress() != null && model.getProjectAddress().size() != 0) {
for (Integer reg : model.getProjectAddress())
for (RegionModel re : list) {
if (re.getRegionCode().equals(Integer.valueOf(reg))) {
area = area + re.getRegionName() + "/";
public ResponseModel<PeasantHouseholdWxDto> wxUserRegister(@ApiParam @RequestBody MobileLoginParamDto mobileLoginParam) {
//注册并登录 生成农户信息表数据
PeasantHouseholdWxDto peasantHouseholdWxDto = peasantHouseholdServiceImpl.registerAndLogin(mobileLoginParam);
PeasantHousehold peasantHousehold = peasantHouseholdWxDto.getPeasantHousehold();
try {
log.info("微信农户注册, 入参 => {}", mobileLoginParam);
PeasantHouseholdDto model = mobileLoginParam.getPeasantHouseholdDto();
validatedPeasantHouseholdDto(model);
BeanDtoUtils.copyPropertiesNonNull(peasantHousehold,model);
model.setPeasantHouseholdNo(peasantHouseholdServiceImpl.getPeasantHouseholdNo(model.getRegionalCompaniesSeq()));
model.setIsCertified(1);// 这里就实名认证
model.setSurveyOrNot(0);
model.setReview(0);
JSONArray regionName = getRegionName();
List<RegionModel> list = JSONArray.parseArray(regionName.toJSONString(), RegionModel.class);
// 处理项目地址
String area = "";
if (model.getProjectAddress() != null && model.getProjectAddress().size() != 0) {
for (Integer reg : model.getProjectAddress())
for (RegionModel re : list) {
if (re.getRegionCode().equals(Integer.valueOf(reg))) {
area = area + re.getRegionName() + "/";
}
}
}
model.setProjectAddressName(area.length() > 2 ? area.substring(0, area.length() - 1) : area);
if ("1".equals(model.getIsPermanent()) || "true".equals(model.getIsPermanent())) {
model.setPermanentAddress(model.getProjectAddress());
model.setPermanentAddressDetail(model.getProjectAddressDetail());
model.setPermanentAddressName(area.length() > 2 ? area.substring(0, area.length() - 1) : area);
} else {
// 处理常住地址
String permanent = "";
if (model.getPermanentAddress() != null && model.getPermanentAddress().size() != 0) {
for (Integer reg : model.getPermanentAddress())
for (RegionModel re : list) {
if (re.getRegionCode().equals(Integer.valueOf(reg))) {
permanent = permanent + re.getRegionName() + "/";
model.setProjectAddressName(area.length() > 2 ? area.substring(0, area.length() - 1) : area);
if ("1".equals(model.getIsPermanent()) || "true".equals(model.getIsPermanent())) {
model.setPermanentAddress(model.getProjectAddress());
model.setPermanentAddressDetail(model.getProjectAddressDetail());
model.setPermanentAddressName(area.length() > 2 ? area.substring(0, area.length() - 1) : area);
} else {
// 处理常住地址
String permanent = "";
if (model.getPermanentAddress() != null && model.getPermanentAddress().size() != 0) {
for (Integer reg : model.getPermanentAddress())
for (RegionModel re : list) {
if (re.getRegionCode().equals(Integer.valueOf(reg))) {
permanent = permanent + re.getRegionName() + "/";
}
}
}
model.setPermanentAddressName(permanent.length() > 2 ? permanent.substring(0, permanent.length() - 1) : permanent);
model.setPermanentAddressName(permanent.length() > 2 ? permanent.substring(0, permanent.length() - 1) : permanent);
}
}
}
BeanDtoUtils.copyPropertiesNonNull(model,peasantHousehold);
PeasantHouseholdDto result = peasantHouseholdServiceImpl.savePeasantHousehold(model, null);
peasantHouseholdWxDto.setPeasantHousehold(peasantHousehold);
return ResponseHelper.buildResponse(peasantHouseholdWxDto);
}catch (Exception e) {
log.error(e.getMessage());
if (null != peasantHousehold) {
log.error("调用平台接口回滚注册的用户 => {}", e, peasantHousehold.getAmosUserId());
// 调用平台接口回滚注册的用户
RequestContext.setAppKey("AMOS_STUDIO");
RequestContext.setProduct("AMOS_STUDIO_WEB");
RequestContext.setToken(requestContext.getToken());
Privilege.agencyUserClient.multDeleteUser(peasantHousehold.getAmosUserId());
}
if (e instanceof BadRequest || e.getCause() instanceof BadRequest) {
throw new BadRequest(e.getMessage());
}
throw new BadRequest(e.getMessage());
}
PeasantHouseholdDto result = peasantHouseholdServiceImpl.savePeasantHousehold(model, userInfo);
return ResponseHelper.buildResponse(result);
}
public JSONArray getRegionName() {
......
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