diff --git a/images/showPic16.png b/images/showPic16.png index 36e6787..fa89b9b 100644 Binary files a/images/showPic16.png and b/images/showPic16.png differ diff --git a/src/main/java/io/linfeng/modules/admin/service/CommentService.java b/src/main/java/io/linfeng/modules/admin/service/CommentService.java index 33f9a8c..e6488db 100644 --- a/src/main/java/io/linfeng/modules/admin/service/CommentService.java +++ b/src/main/java/io/linfeng/modules/admin/service/CommentService.java @@ -35,8 +35,6 @@ public interface CommentService extends IService { Integer getCountByTopicId(Integer id); - List getByPid(Long pid); - void deleteByAdmin(List longs); Integer getCountByPostId(Integer id); diff --git a/src/main/java/io/linfeng/modules/admin/service/impl/AppUserServiceImpl.java b/src/main/java/io/linfeng/modules/admin/service/impl/AppUserServiceImpl.java index e0e3265..62aa05b 100644 --- a/src/main/java/io/linfeng/modules/admin/service/impl/AppUserServiceImpl.java +++ b/src/main/java/io/linfeng/modules/admin/service/impl/AppUserServiceImpl.java @@ -32,7 +32,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + import java.util.*; + import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -68,12 +70,12 @@ public class AppUserServiceImpl extends ServiceImpl i @Override public PageUtils queryPage(Map params) { - QueryWrapper queryWrapper=new QueryWrapper<>(); + QueryWrapper queryWrapper = new QueryWrapper<>(); //模糊查询 - String key = (String)params.get("key"); - if(!WechatUtil.isEmpty(key)){ - params.put("page","1");//如果是查询分页重置为第一页 - queryWrapper.like("username", key).or().like("mobile",key); + String key = (String) params.get("key"); + if (!WechatUtil.isEmpty(key)) { + params.put("page", "1");//如果是查询分页重置为第一页 + queryWrapper.like("username", key).or().like("mobile", key); } queryWrapper.lambda().orderByDesc(AppUserEntity::getUid); IPage page = this.page( @@ -87,24 +89,24 @@ public class AppUserServiceImpl extends ServiceImpl i @Override public void ban(Integer id) { Integer status = this.lambdaQuery().eq(AppUserEntity::getUid, id).one().getStatus(); - if(status.equals(Constant.USER_BANNER)){ + if (status.equals(Constant.USER_BANNER)) { throw new LinfengException("该用户已被禁用"); } this.lambdaUpdate() - .set(AppUserEntity::getStatus,1) - .eq(AppUserEntity::getUid,id) + .set(AppUserEntity::getStatus, 1) + .eq(AppUserEntity::getUid, id) .update(); } @Override public void openBan(Integer id) { Integer status = this.lambdaQuery().eq(AppUserEntity::getUid, id).one().getStatus(); - if(status.equals(Constant.USER_NORMAL)){ + if (status.equals(Constant.USER_NORMAL)) { throw new LinfengException("该用户已解除禁用"); } this.lambdaUpdate() - .set(AppUserEntity::getStatus,0) - .eq(AppUserEntity::getUid,id) + .set(AppUserEntity::getStatus, 0) + .eq(AppUserEntity::getUid, id) .update(); } @@ -123,59 +125,60 @@ public class AppUserServiceImpl extends ServiceImpl i return response; } - @Override - public Integer smsLogin(SmsLoginForm form, HttpServletRequest request) { - AppUserEntity appUserEntity = this.lambdaQuery().eq(AppUserEntity::getMobile, form.getMobile()).one(); - String codeKey="code_"+form.getMobile(); - String s = redisUtils.get(codeKey); - if(!s.equals(form.getCode())){ - throw new LinfengException("验证码错误"); - } - if(ObjectUtil.isNotNull(appUserEntity)){ - //登录 - if(appUserEntity.getStatus()==1){ - throw new LinfengException("该账户已被禁用"); - } - return appUserEntity.getUid(); - }else{ - //注册 - AppUserEntity appUser=new AppUserEntity(); - appUser.setMobile(form.getMobile()); - appUser.setGender(0); - appUser.setAvatar(Constant.DEAULT_HEAD); - appUser.setUsername("LF_"+RandomUtil.randomNumbers(8)); - appUser.setCreateTime(DateUtil.nowDateTime()); - appUser.setUpdateTime(DateUtil.nowDateTime()); - List list=new ArrayList<>(); - list.add("新人"); - appUser.setTagStr(JSON.toJSONString(list)); - baseMapper.insert(appUser); - AppUserEntity user=this.lambdaQuery().eq(AppUserEntity::getMobile,form.getMobile()).one(); - return user.getUid(); - } - - + @Override + public Integer smsLogin(SmsLoginForm form, HttpServletRequest request) { + AppUserEntity appUserEntity = this.lambdaQuery().eq(AppUserEntity::getMobile, form.getMobile()).one(); + String codeKey = "code_" + form.getMobile(); + String s = redisUtils.get(codeKey); + if (!s.equals(form.getCode())) { + throw new LinfengException("验证码错误"); } + if (ObjectUtil.isNotNull(appUserEntity)) { + //登录 + if (appUserEntity.getStatus() == 1) { + throw new LinfengException("该账户已被禁用"); + } + return appUserEntity.getUid(); + } else { + //注册 + AppUserEntity appUser = new AppUserEntity(); + appUser.setMobile(form.getMobile()); + appUser.setGender(0); + appUser.setAvatar(Constant.DEAULT_HEAD); + appUser.setUsername("LF_" + RandomUtil.randomNumbers(8)); + appUser.setCreateTime(DateUtil.nowDateTime()); + appUser.setUpdateTime(DateUtil.nowDateTime()); + List list = new ArrayList<>(); + list.add("新人"); + appUser.setTagStr(JSON.toJSONString(list)); + baseMapper.insert(appUser); + 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 codeKey = "code_" + param.getMobile(); String s = redisUtils.get(codeKey); - if(ObjectUtil.isNotNull(s)){ + if (ObjectUtil.isNotNull(s)) { return s; } - redisUtils.set(codeKey,code,60*5); + 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()); + + 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); @@ -184,23 +187,23 @@ public class AppUserServiceImpl extends ServiceImpl i @Override public void updateAppUserInfo(AppUserUpdateForm appUserUpdateForm, AppUserEntity user) { - if(!WechatUtil.isEmpty(appUserUpdateForm.getAvatar())){ + if (!WechatUtil.isEmpty(appUserUpdateForm.getAvatar())) { user.setAvatar(appUserUpdateForm.getAvatar()); } baseMapper.updateById(user); - redisUtils.delete("userId:"+user.getUid()); + redisUtils.delete("userId:" + user.getUid()); } @Override public void addFollow(AddFollowForm request, AppUserEntity user) { - if(request.getId().equals(user.getUid())){ + if (request.getId().equals(user.getUid())) { throw new LinfengException("不能关注自己哦"); } - boolean isFollow=followService.isFollowOrNot(user.getUid(),request.getId()); - if(isFollow){ + boolean isFollow = followService.isFollowOrNot(user.getUid(), request.getId()); + if (isFollow) { throw new LinfengException("不要重复关注哦"); } - FollowEntity followEntity=new FollowEntity(); + FollowEntity followEntity = new FollowEntity(); followEntity.setUid(user.getUid()); followEntity.setFollowUid(request.getId()); followEntity.setCreateTime(DateUtil.nowDateTime()); @@ -210,11 +213,12 @@ public class AppUserServiceImpl extends ServiceImpl i @Override public void cancelFollow(AddFollowForm request, AppUserEntity user) { - followDao.cancelFollow(user.getUid(),request.getId()); + followDao.cancelFollow(user.getUid(), request.getId()); } + @Override public AppPageUtils userFans(Integer currPage, Integer uid) { - List uidList=followService.getFansList(uid); + List uidList = followService.getFansList(uid); if (uidList.isEmpty()) { return new AppPageUtils(null, 0, 10, currPage); } @@ -266,8 +270,8 @@ public class AppUserServiceImpl extends ServiceImpl i @Override public AppUserInfoResponse findUserInfoById(Integer uid, AppUserEntity user) { AppUserEntity userEntity = this.getById(uid); - AppUserInfoResponse response=new AppUserInfoResponse(); - BeanUtils.copyProperties(userEntity,response); + AppUserInfoResponse response = new AppUserInfoResponse(); + BeanUtils.copyProperties(userEntity, response); return response; } @@ -283,38 +287,37 @@ public class AppUserServiceImpl extends ServiceImpl i //授权(必填) String grant_type = "authorization_code"; //https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code - //1、向微信服务器 使用登录凭证 code 获取 session_key 和 openid - //请求参数 + //向微信服务器 使用登录凭证 code 获取 session_key 和 openid String params = "appid=" + appId + "&secret=" + secret + "&js_code=" + form.getCode() + "&grant_type=" + grant_type; //发送请求 String sr = HttpRequest.sendGet("https://api.weixin.qq.com/sns/jscode2session", params); //解析相应内容(转换成json对象) - JSONObject json =JSON.parseObject(sr); + JSONObject json = JSON.parseObject(sr); //用户的唯一标识(openId) String openId = (String) json.get("openid"); //根据openId获取数据库信息 判断用户是否登录 AppUserEntity user = this.lambdaQuery().eq(AppUserEntity::getOpenid, openId).one(); - if(ObjectUtil.isNotNull(user)){ + if (ObjectUtil.isNotNull(user)) { //已登录用户 - if(user.getStatus()==1){ + if (user.getStatus() == 1) { throw new LinfengException("该账户已被禁用"); } + //其他业务todo return user.getUid(); - }else{ + } else { //新注册用户 - //注册 - AppUserEntity appUser=new AppUserEntity(); + AppUserEntity appUser = new AppUserEntity(); appUser.setGender(0); appUser.setAvatar(form.getAvatar()); appUser.setUsername(form.getUsername()); appUser.setCreateTime(DateUtil.nowDateTime()); appUser.setUpdateTime(DateUtil.nowDateTime()); appUser.setOpenid(openId); - List list=new ArrayList<>(); + List list = new ArrayList<>(); list.add("新人"); appUser.setTagStr(JSON.toJSONString(list)); baseMapper.insert(appUser); - AppUserEntity users=this.lambdaQuery().eq(AppUserEntity::getOpenid,openId).one(); + AppUserEntity users = this.lambdaQuery().eq(AppUserEntity::getOpenid, openId).one(); return users.getUid(); } } diff --git a/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java b/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java index 6ccea34..bd5b3d4 100644 --- a/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java +++ b/src/main/java/io/linfeng/modules/admin/service/impl/CommentServiceImpl.java @@ -66,13 +66,6 @@ public class CommentServiceImpl extends ServiceImpl i .eq(CommentEntity::getPostId, id)); } - @Override - public List getByPid(Long pid) { - return baseMapper.selectList( - new LambdaQueryWrapper() - .eq(CommentEntity::getPid, pid)); - } - /** * 管理端批量删除评论 diff --git a/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java b/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java index 04c0d76..4bee180 100644 --- a/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java +++ b/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java @@ -13,25 +13,18 @@ package io.linfeng.modules.admin.service.impl; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.linfeng.common.exception.LinfengException; import io.linfeng.common.response.PostDetailResponse; import io.linfeng.common.response.PostListResponse; -import io.linfeng.common.response.TopicDetailResponse; import io.linfeng.common.utils.*; import io.linfeng.modules.admin.entity.*; import io.linfeng.modules.admin.service.*; import io.linfeng.modules.app.entity.PostCollectionEntity; -import io.linfeng.modules.app.entity.TopicAdminEntity; -import io.linfeng.modules.app.entity.UserTopicEntity; import io.linfeng.modules.app.form.*; import io.linfeng.modules.app.service.*; import io.linfeng.modules.app.utils.LocalUser; -import javafx.geometry.Pos; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,8 +32,6 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -63,8 +54,6 @@ public class PostServiceImpl extends ServiceImpl implements @Autowired private DiscussService discussService; @Autowired - private MessageService messageService; - @Autowired private LocalUser localUser; @Autowired private FollowService followService; @@ -116,7 +105,7 @@ public class PostServiceImpl extends ServiceImpl implements @Override - @Transactional + @Transactional(rollbackFor = Exception.class) public void deleteByAdmin(List ids) { boolean remove = this.removeByIds(ids); @@ -240,6 +229,7 @@ public class PostServiceImpl extends ServiceImpl implements } @Override + @Transactional(rollbackFor = Exception.class) public Integer addPost(AddPostForm request, AppUserEntity user) { if(user.getStatus()!=0){ throw new LinfengException("您的账号已被禁用"); diff --git a/src/main/java/io/linfeng/modules/app/controller/AppLoginController.java b/src/main/java/io/linfeng/modules/app/controller/AppLoginController.java index 7c3be16..1a96f9f 100644 --- a/src/main/java/io/linfeng/modules/app/controller/AppLoginController.java +++ b/src/main/java/io/linfeng/modules/app/controller/AppLoginController.java @@ -33,6 +33,7 @@ import java.util.Map; /** * APP登录接口 + * * @author linfeng * @date 2022/6/9 22:40 */ @@ -51,23 +52,21 @@ public class AppLoginController { @PostMapping("/sendSmsCode") @ApiOperation("发送验证码") - public R sendSmsCode(@RequestBody SendCodeForm param){ - String code=appUserService.sendSmsCode(param); - return R.ok("测试阶段验证码:"+code); + public R sendSmsCode(@RequestBody SendCodeForm param) { + String code = appUserService.sendSmsCode(param); + return R.ok("测试阶段验证码:" + code); } - - /** * 手机验证码登录 */ @PostMapping("/smsLogin") @ApiOperation("手机验证码登录") - public R smsLogin(@RequestBody SmsLoginForm form, HttpServletRequest request){ + public R smsLogin(@RequestBody SmsLoginForm form, HttpServletRequest request) { //用户登录 - Integer userId = appUserService.smsLogin(form,request); + Integer userId = appUserService.smsLogin(form, request); //生成token String token = jwtUtils.generateToken(userId); @@ -84,7 +83,7 @@ public class AppLoginController { */ @PostMapping("/miniWxlogin") @ApiOperation("手机验证码登录") - public R miniWxLogin(@RequestBody WxLoginForm form){ + public R miniWxLogin(@RequestBody WxLoginForm form) { //用户登录 Integer userId = appUserService.miniWxLogin(form); @@ -100,14 +99,12 @@ public class AppLoginController { } - - @Login @GetMapping("/userInfo") @ApiOperation("获取用户信息") - public R userInfo(@LoginUser AppUserEntity user){ + public R userInfo(@LoginUser AppUserEntity user) { - AppUserResponse response=appUserService.getUserInfo(user); + AppUserResponse response = appUserService.getUserInfo(user); return R.ok().put("result", response); } @@ -115,18 +112,17 @@ public class AppLoginController { @Login @PostMapping("/userInfoEdit") @ApiOperation("用户修改个人信息") - public R userInfoEdit(@LoginUser AppUserEntity user, @RequestBody AppUserUpdateForm appUserUpdateForm){ - appUserService.updateAppUserInfo(appUserUpdateForm,user); + public R userInfoEdit(@LoginUser AppUserEntity user, @RequestBody AppUserUpdateForm appUserUpdateForm) { + appUserService.updateAppUserInfo(appUserUpdateForm, user); return R.ok("修改成功"); } - @Login @PostMapping("/addFollow") @ApiOperation("关注用户") - public R addFollow(@LoginUser AppUserEntity user, @RequestBody AddFollowForm request){ - appUserService.addFollow(request,user); + public R addFollow(@LoginUser AppUserEntity user, @RequestBody AddFollowForm request) { + appUserService.addFollow(request, user); return R.ok("关注用户成功"); } @@ -134,25 +130,26 @@ public class AppLoginController { @Login @PostMapping("/cancelFollow") @ApiOperation("取消关注用户") - public R cancelFollow(@LoginUser AppUserEntity user, @RequestBody AddFollowForm request){ - appUserService.cancelFollow(request,user); + public R cancelFollow(@LoginUser AppUserEntity user, @RequestBody AddFollowForm request) { + appUserService.cancelFollow(request, user); return R.ok("取消关注用户成功"); } + @Login @GetMapping("/userFans") @ApiOperation("我的粉丝分页列表") - public R userFans(@RequestParam("page") Integer page,@LoginUser AppUserEntity user){ + public R userFans(@RequestParam("page") Integer page, @LoginUser AppUserEntity user) { - AppPageUtils pages =appUserService.userFans(page,user.getUid()); + AppPageUtils pages = appUserService.userFans(page, user.getUid()); return R.ok().put("result", pages); } @Login @GetMapping("/follow") @ApiOperation("我的关注分页列表") - public R follow(@RequestParam("page") Integer page,@LoginUser AppUserEntity user){ + public R follow(@RequestParam("page") Integer page, @LoginUser AppUserEntity user) { - AppPageUtils pages =appUserService.follow(page,user); + AppPageUtils pages = appUserService.follow(page, user); return R.ok().put("result", pages); } @@ -160,9 +157,9 @@ public class AppLoginController { @Login @PostMapping("/userInfoById") @ApiOperation("用户个人主页信息") - public R userInfoById(@RequestBody AppUserInfoForm request, @LoginUser AppUserEntity user){ - AppUserInfoResponse response=appUserService.findUserInfoById(request.getUid(),user); + public R userInfoById(@RequestBody AppUserInfoForm request, @LoginUser AppUserEntity user) { + AppUserInfoResponse response = appUserService.findUserInfoById(request.getUid(), user); - return R.ok().put("result",response); + return R.ok().put("result", response); } } diff --git a/src/main/java/io/linfeng/modules/app/controller/AppOssController.java b/src/main/java/io/linfeng/modules/app/controller/AppOssController.java index c3e4c3e..f4e3a12 100644 --- a/src/main/java/io/linfeng/modules/app/controller/AppOssController.java +++ b/src/main/java/io/linfeng/modules/app/controller/AppOssController.java @@ -41,9 +41,6 @@ public class AppOssController { @Value("${qiniu.max-size}") private Long maxSize; - @Autowired - private SysOssService sysOssService; - @ApiOperation("上传文件") @PostMapping("/upload") @@ -56,12 +53,6 @@ public class AppOssController { String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); String url = OSSFactory.build().uploadSuffix(file.getBytes(), suffix); - //保存文件信息 - SysOssEntity ossEntity = new SysOssEntity(); - ossEntity.setUrl(url); - ossEntity.setCreateDate(new Date()); - sysOssService.save(ossEntity); - return R.ok().put("result", url); } diff --git a/src/main/java/io/linfeng/modules/app/controller/AppPostController.java b/src/main/java/io/linfeng/modules/app/controller/AppPostController.java index 9264320..b741830 100644 --- a/src/main/java/io/linfeng/modules/app/controller/AppPostController.java +++ b/src/main/java/io/linfeng/modules/app/controller/AppPostController.java @@ -138,7 +138,7 @@ public class AppPostController { ValidatorUtils.validateEntity(request); Integer id=postService.addPost(request,user); if(id==0){ - return R.error(); + return R.error("发帖失败"); } return R.ok().put("result",id); } diff --git a/src/main/java/io/linfeng/modules/app/controller/AppSystemConfigController.java b/src/main/java/io/linfeng/modules/app/controller/AppSystemConfigController.java index f436ae4..fa871f7 100644 --- a/src/main/java/io/linfeng/modules/app/controller/AppSystemConfigController.java +++ b/src/main/java/io/linfeng/modules/app/controller/AppSystemConfigController.java @@ -14,7 +14,6 @@ package io.linfeng.modules.app.controller; import io.linfeng.common.utils.R; import io.linfeng.modules.admin.entity.SystemEntity; import io.linfeng.modules.admin.service.SystemService; -import io.linfeng.modules.sys.service.SysConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -34,7 +33,9 @@ public class AppSystemConfigController { @GetMapping("/miniConfig") public R miniConfig(){ - SystemEntity system = systemService.lambdaQuery().eq(SystemEntity::getConfig, "miniapp").one(); + SystemEntity system = systemService.lambdaQuery() + .eq(SystemEntity::getConfig, "miniapp") + .one(); return R.ok().put("logo",system.getIntro()); } diff --git a/src/main/java/io/linfeng/modules/app/service/impl/CommentThumbsServiceImpl.java b/src/main/java/io/linfeng/modules/app/service/impl/CommentThumbsServiceImpl.java index ec0e23e..6757afa 100644 --- a/src/main/java/io/linfeng/modules/app/service/impl/CommentThumbsServiceImpl.java +++ b/src/main/java/io/linfeng/modules/app/service/impl/CommentThumbsServiceImpl.java @@ -55,8 +55,9 @@ public class CommentThumbsServiceImpl extends ServiceImpl