资金记录
需求
后端
controller
TransFlowController.java
package com.indi.srb.core.controller.api;
@Api(tags = "资金记录")
@RestController
@RequestMapping("/api/core/transFlow")
@Slf4j
public class TransFlowController {
@Resource
private TransFlowService transFlowService;
@ApiOperation("获取列表")
@GetMapping("/list")
public R list(HttpServletRequest request){
String token = request.getHeader("token");
Long userId = JwtUtils.getUserId(token);
List<TransFlow> transFlowList = transFlowService.listByUserId(userId);
return R.ok().setData("list",transFlowList);
}
}
service
TransFlowService.java
List<TransFlow> listByUserId(Long userId);
TransFlowServiceImpl.java
@Override
public List<TransFlow> listByUserId(Long userId) {
QueryWrapper<TransFlow> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id",userId).orderByDesc("id");
return baseMapper.selectList(queryWrapper);
}
前端
script
pages/user/fund.vue
methods: {
fetchTransFlowList() {
this.$axios.$get('/api/core/transFlow/list').then((response) => {
this.transFlowList = response.data.list
})
},
},
个人中心首页
需求
后端
vo
UserIndexVO.java
package com.indi.srb.core.pojo.vo;
@Data
@ApiModel(description = "首页用户信息")
public class UserIndexVO {
@ApiModelProperty(value = "用户id")
private Long userId;
@ApiModelProperty(value = "用户姓名")
private String name;
@ApiModelProperty(value = "用户昵称")
private String nickName;
@ApiModelProperty(value = "1:出借人 2:借款人")
private Integer userType;
@ApiModelProperty(value = "用户头像")
private String headImg;
@ApiModelProperty(value = "绑定状态(0:未绑定,1:绑定成功 -1:绑定失败)")
private Integer bindStatus;
@ApiModelProperty(value = "帐户可用余额")
private BigDecimal amount;
@ApiModelProperty(value = "冻结金额")
private BigDecimal freezeAmount;
@ApiModelProperty(value = "上次登录时间")
private LocalDateTime lastLoginTime;
}
controller
UserInfoController.java
@ApiOperation("获取个人空间用户信息")
@GetMapping("/auth/getIndexUserInfo")
public R getIndexUserInfo(HttpServletRequest request){
String token = request.getHeader("token");
Long userId = JwtUtils.getUserId(token);
UserIndexVO userIndexVO = userInfoService.getIndexUserInfo(userId);
return R.ok().setData("userIndexVO",userIndexVO);
}
service
UserInfoService.java
UserIndexVO getIndexUserInfo(Long userId);
UserInfoServiceImpl.java
@Override
public UserIndexVO getIndexUserInfo(Long userId) {
// 用户信息
UserInfo userInfo = baseMapper.selectById(userId);
// 账户信息
QueryWrapper<UserAccount> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id",userId);
UserAccount userAccount = userAccountMapper.selectOne(queryWrapper);
// 登录信息
QueryWrapper<UserLoginRecord> recordQueryWrapper = new QueryWrapper<>();
recordQueryWrapper.eq("user_id",userId)
.orderByDesc("id")
.last("limit 1");
UserLoginRecord userLoginRecord = userLoginRecordMapper.selectOne(recordQueryWrapper);
UserIndexVO userIndexVO = new UserIndexVO();
userIndexVO.setUserId(userInfo.getId());
userIndexVO.setName(userInfo.getName());
userIndexVO.setNickName(userInfo.getNickName());
userIndexVO.setUserType(userInfo.getUserType());
userIndexVO.setHeadImg(userInfo.getHeadImg());
userIndexVO.setBindStatus(userInfo.getBindStatus());
userIndexVO.setAmount(userAccount.getAmount());
userIndexVO.setFreezeAmount(userAccount.getFreezeAmount());
userIndexVO.setLastLoginTime(userLoginRecord.getCreateTime());
return userIndexVO;
}
前端
script
pages/user/index.vue
// created()里面的方法移到mounted()里面
mounted() {
this.fetchUserData()
},
methods: {
fetchUserData() {
this.$axios
.$get('/api/core/userInfo/auth/getIndexUserInfo')
.then((response) => {
this.userIndexVO = response.data.userIndexVO
})
},
},