登录和个人页面后端接口

This commit is contained in:
linfeng 2022-07-27 13:11:20 +08:00
parent 2f36d725b7
commit 5e4e5c76f6
9 changed files with 140 additions and 33 deletions

View File

@ -36,5 +36,11 @@ public interface AppUserService extends IService<AppUserEntity> {
HomeRateResponse indexDate();
Integer smsLogin(SmsLoginForm form, HttpServletRequest request);
String sendSmsCode(SendCodeForm param);
AppUserResponse getUserInfo(AppUserEntity user);
void updateAppUserInfo(AppUserUpdateForm appUserUpdateForm, AppUserEntity user);
}

View File

@ -28,5 +28,7 @@ public interface PostService extends IService<PostEntity> {
List<String> findThreeMedia(Integer id);
void deleteByAdmin(List<Integer> integers);
Integer getPostNumByUid(Integer uid);
}

View File

@ -1,14 +1,20 @@
package io.linfeng.modules.admin.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.linfeng.common.exception.LinfengException;
import io.linfeng.common.response.AppUserResponse;
import io.linfeng.common.response.HomeRateResponse;
import io.linfeng.common.utils.*;
import io.linfeng.modules.admin.entity.PostEntity;
import io.linfeng.modules.admin.service.*;
import io.linfeng.modules.app.form.AppUserUpdateForm;
import io.linfeng.modules.app.form.SendCodeForm;
import io.linfeng.modules.app.form.SmsLoginForm;
import io.linfeng.modules.app.service.FollowService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@ -34,6 +40,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
@Autowired
private RedisUtils redisUtils;
@Autowired
private FollowService followService;
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<AppUserEntity> queryWrapper=new QueryWrapper<>();
@ -94,35 +103,69 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
@Override
public Integer smsLogin(SmsLoginForm form, HttpServletRequest request) {
AppUserEntity appUserEntity = this.lambdaQuery().eq(AppUserEntity::getMobile, form.getMobile()).one();
String codeKey = "code_" + form.getMobile();
String codeKey="code_"+form.getMobile();
String s = redisUtils.get(codeKey);
if(!s.equals(form.getCode())){
throw new LinfengException("验证码错误");
throw new LinfengException("验证码错误");
}
if(appUserEntity!=null){
if(ObjectUtil.isNotNull(appUserEntity)){
//登录
if(appUserEntity.getStatus()==1){
throw new LinfengException("该账已被禁用");
throw new LinfengException("该账已被禁用");
}
return appUserEntity.getUid();
}else {
List<String> list=new ArrayList<>();
list.add("萌新");
AppUserEntity appUser = new AppUserEntity();
}else{
//注册
AppUserEntity appUser=new AppUserEntity();
appUser.setMobile(form.getMobile());
appUser.setAvatar(Constant.DEAULT_HEAD);
appUser.setGender(0);
appUser.setUsername("LF_"+RandomUtil.randomNumbers(6));
String tag = JSON.toJSONString(list);
appUser.setTagStr(tag);
appUser.setAvatar(Constant.DEAULT_HEAD);
appUser.setUsername("LF_"+RandomUtil.randomNumbers(8));
appUser.setCreateTime(DateUtil.nowDateTime());
appUser.setUpdateTime(DateUtil.nowDateTime());
baseMapper.insert(appUser);
AppUserEntity appUsers = this.lambdaQuery().eq(AppUserEntity::getMobile, form.getMobile()).one();
return appUsers.getUid();
List<String> list=new ArrayList<>();
list.add("新人");
appUser.setTagStr(JSON.toJSONString(list));
baseMapper.insert(appUserEntity);
AppUserEntity user=this.lambdaQuery().eq(AppUserEntity::getMobile,form.getMobile()).one();
return user.getUid();
}
}
@Override
public String sendSmsCode(SendCodeForm param) {
String code = RandomUtil.randomNumbers(6);
String codeKey="code_"+param.getMobile();
String s = redisUtils.get(codeKey);
if(ObjectUtil.isNotNull(s)){
return s;
}
redisUtils.set(codeKey,code,60*5);
return code;
}
@Override
public AppUserResponse getUserInfo(AppUserEntity user) {
AppUserResponse response=new AppUserResponse();
BeanUtils.copyProperties(user,response);
Integer follow=followService.getFollowCount(user.getUid());
Integer fans=followService.getFans(user.getUid());
Integer postNum=postService.getPostNumByUid(user.getUid());
response.setFans(fans);
response.setPostNum(postNum);
response.setFollow(follow);
return response;
}
@Override
public void updateAppUserInfo(AppUserUpdateForm appUserUpdateForm, AppUserEntity user) {
if(!WechatUtil.isEmpty(appUserUpdateForm.getAvatar())){
user.setAvatar(appUserUpdateForm.getAvatar());
}
baseMapper.updateById(user);
redisUtils.delete("userId:"+user.getUid());
}
private Integer getTotalNum() {

View File

@ -148,4 +148,11 @@ public class PostServiceImpl extends ServiceImpl<PostDao, PostEntity> implements
}
}
@Override
public Integer getPostNumByUid(Integer uid) {
return this.lambdaQuery().eq(PostEntity::getUid,uid)
.count();
}
}

View File

@ -1,17 +1,21 @@
package io.linfeng.modules.app.controller;
import io.linfeng.common.response.AppUserResponse;
import io.linfeng.common.utils.R;
import io.linfeng.common.utils.RedisUtils;
import io.linfeng.common.validator.ValidatorUtils;
import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.admin.service.AppUserService;
import io.linfeng.modules.app.annotation.Login;
import io.linfeng.modules.app.annotation.LoginUser;
import io.linfeng.modules.app.form.AppUserUpdateForm;
import io.linfeng.modules.app.form.SendCodeForm;
import io.linfeng.modules.app.form.SmsLoginForm;
import io.linfeng.modules.app.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
@ -34,11 +38,14 @@ public class AppLoginController {
@Autowired
private AppUserService appUserService;
@Autowired
private RedisUtils redisUtils;
@PostMapping("/sendSmsCode")
@ApiOperation("发送验证码")
public R sendSmsCode(@RequestBody SendCodeForm param){
String code=appUserService.sendSmsCode(param);
return R.ok("测试阶段验证码:"+code);
}
@ -63,4 +70,23 @@ public class AppLoginController {
return R.ok(map);
}
@Login
@GetMapping("/userInfo")
@ApiOperation("获取用户信息")
public R userInfo(@LoginUser AppUserEntity user){
AppUserResponse response=appUserService.getUserInfo(user);
return R.ok().put("result", response);
}
@Login
@PostMapping("/userInfoEdit")
@ApiOperation("用户修改个人信息")
public R userInfoEdit(@LoginUser AppUserEntity user, @RequestBody AppUserUpdateForm appUserUpdateForm){
appUserService.updateAppUserInfo(appUserUpdateForm,user);
return R.ok("修改成功");
}
}

View File

@ -20,13 +20,4 @@ public class AppUserUpdateForm {
@ApiModelProperty(value = "头像")
private String avatar;
@ApiModelProperty(value = "性别")
private Integer gender;
@ApiModelProperty(value = "标签")
private List<String> tagStr;
@ApiModelProperty(value = "个性签名")
@Length(max = 20, message = "个性签名不能超过20个字符")
private String intro;
}

View File

@ -0,0 +1,18 @@
package io.linfeng.modules.app.form;
/**
* @author linfeng
* @date 2022/7/27 11:12
*/
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "手机验证码")
public class SendCodeForm {
@ApiModelProperty(value = "手机号")
private String mobile;
}

View File

@ -19,5 +19,8 @@ public interface FollowService extends IService<FollowEntity> {
PageUtils queryPage(Map<String, Object> params);
Integer getFollowCount(Integer uid);
Integer getFans(Integer uid);
}

View File

@ -25,4 +25,15 @@ public class FollowServiceImpl extends ServiceImpl<FollowDao, FollowEntity> impl
return new PageUtils(page);
}
@Override
public Integer getFollowCount(Integer uid) {
return this.lambdaQuery().eq(FollowEntity::getUid, uid).count();
}
@Override
public Integer getFans(Integer uid) {
return this.lambdaQuery().eq(FollowEntity::getFollowUid,uid).count();
}
}