认清现实,放弃幻想,准备斗争
一、后端开发
1、定义VO对象
service-core微服务,创建BorrowerVO
@Data @ApiModel(description="借款人认证信息") public class BorrowerVO { @ApiModelProperty(value = "性别(1:男 0:女)") private Integer sex; @ApiModelProperty(value = "年龄") private Integer age; @ApiModelProperty(value = "学历") private Integer education; @ApiModelProperty(value = "是否结婚(1:是 0:否)") private Boolean marry; @ApiModelProperty(value = "行业") private Integer industry; @ApiModelProperty(value = "月收入") private Integer income; @ApiModelProperty(value = "还款来源") private Integer returnSource; @ApiModelProperty(value = "联系人名称") private String contactsName; @ApiModelProperty(value = "联系人手机") private String contactsMobile; @ApiModelProperty(value = "联系人关系") private Integer contactsRelation; @ApiModelProperty(value = "借款人附件资料") private List<BorrowerAttach> borrowerAttachList; }
2、定义枚举
BorrowerStatusEnum
数据库设计中对应认证状态status (0:未认证,1:认证中, 2:认证通过, -1:认证失败)
3、controller
service-core中在BorrowerController中定义接口方法
@Api(tags = "借款人") @RestController @RequestMapping("/api/core/borrower") @Slf4j public class BorrowerController { @Resource private BorrowerService borrowerService; @ApiOperation("保存借款人信息") @PostMapping("/auth/save") public R save(@RequestBody BorrowerVO borrowerVO, HttpServletRequest request) { String token = request.getHeader("token"); Long userId = JwtUtils.getUserId(token); borrowerService.saveBorrowerVOByUserId(borrowerVO, userId); return R.ok().message("信息提交成功"); } }
6、service
接口:BorrowerService
void saveBorrowerVOByUserId(BorrowerVO borrowerVO, Long userId);
实现:BorrowerServiceImpl
@Resource private BorrowerAttachMapper borrowerAttachMapper; @Resource private UserInfoMapper userInfoMapper; @Transactional(rollbackFor = Exception.class) @Override public void saveBorrowerVOByUserId(BorrowerVO borrowerVO, Long userId) { UserInfo userInfo = userInfoMapper.selectById(userId); //保存借款人信息 Borrower borrower = new Borrower(); BeanUtils.copyProperties(borrowerVO, borrower); borrower.setUserId(userId); borrower.setName(userInfo.getName()); borrower.setIdCard(userInfo.getIdCard()); borrower.setMobile(userInfo.getMobile()); borrower.setStatus(BorrowerStatusEnum.AUTH_RUN.getStatus());//认证中 baseMapper.insert(borrower); //保存附件 List<BorrowerAttach> borrowerAttachList = borrowerVO.getBorrowerAttachList(); borrowerAttachList.forEach(borrowerAttach -> { borrowerAttach.setBorrowerId(borrower.getId()); borrowerAttachMapper.insert(borrowerAttach); }); //更新会员状态,更新为认证中 userInfo.setBorrowAuthStatus(BorrowerStatusEnum.AUTH_RUN.getStatus()); userInfoMapper.updateById(userInfo); }
二、前端整合
pages/user/borrower.vue 脚本
save() { // debugger this.submitBtnDisabled = true this.$axios .$post('/api/core/borrower/save', this.borrower) .then((response) => { this.active = 1 }) },
一、获取借款人状态
1、BorrowerController
@ApiOperation("获取借款人认证状态") @GetMapping("/auth/getBorrowerStatus") public R getBorrowerStatus(HttpServletRequest request){ String token = request.getHeader("token"); Long userId = JwtUtils.getUserId(token); Integer status = borrowerService.getStatusByUserId(userId); return R.ok().data("borrowerStatus", status); }
2、service
接口:BorrowerService
Integer getStatusByUserId(Long userId);
实现:BorrowerServiceImpl
@Override public Integer getStatusByUserId(Long userId) { QueryWrapper<Borrower> borrowerQueryWrapper = new QueryWrapper<>(); borrowerQueryWrapper.select("status").eq("user_id", userId); List<Object> objects = baseMapper.selectObjs(borrowerQueryWrapper); if(objects.size() == 0){ //借款人尚未提交信息 return BorrowerStatusEnum.NO_AUTH.getStatus(); } Integer status = (Integer)objects.get(0); return status; }
二、前端开发
pages/user/borrower.vue 脚本
将this.initSelected()在this.getUserInfo()中调用
methods中添加方法:
//获取借款人信息 getUserInfo() { this.$axios .$get('/api/core/borrower/auth/getBorrowerStatus') .then((response) => { this.borrowerStatus = response.data.borrowerStatus if (this.borrowerStatus === 0) { //未认证 this.active = 0 //获取下拉列表 this.initSelected() } else if (this.borrowerStatus === 1) { //认证中 this.active = 1 } else if (this.borrowerStatus === 2) { //认证成功 this.active = 2 } else if (this.borrowerStatus === -1) { //认证失败 this.active = 2 } }) }
将 data() 中 active的初始化值设置为null
active: null, //步