Merge branch 'develop' of https://gitee.com/likeshop_gitee/likeadmin-java into develop
* 'develop' of https://gitee.com/likeshop_gitee/likeadmin-java: 增加注册时的客户端 增加文章收藏处理 增加收藏 调整接口
This commit is contained in:
commit
b96c43e051
|
|
@ -8,6 +8,7 @@ import com.mdd.common.entity.user.User;
|
||||||
import com.mdd.common.enums.HttpEnum;
|
import com.mdd.common.enums.HttpEnum;
|
||||||
import com.mdd.common.mapper.user.UserMapper;
|
import com.mdd.common.mapper.user.UserMapper;
|
||||||
import com.mdd.common.utils.RedisUtil;
|
import com.mdd.common.utils.RedisUtil;
|
||||||
|
import com.mdd.common.utils.StringUtil;
|
||||||
import com.mdd.front.config.FrontConfig;
|
import com.mdd.front.config.FrontConfig;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -45,13 +46,21 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 免登录接口
|
// 免登录接口
|
||||||
|
String token = request.getHeader("token");
|
||||||
List<String> notLoginUri = Arrays.asList(FrontConfig.notLoginUri);
|
List<String> notLoginUri = Arrays.asList(FrontConfig.notLoginUri);
|
||||||
if (notLoginUri.contains(request.getRequestURI())) {
|
if (notLoginUri.contains(request.getRequestURI())) {
|
||||||
|
if (StringUtil.isNotEmpty(token)) {
|
||||||
|
Object uid = RedisUtil.get(token);
|
||||||
|
if (uid != null) {
|
||||||
|
Integer userId = Integer.parseInt(uid.toString());
|
||||||
|
LikeFrontThreadLocal.put("userId", userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Token是否为空
|
// Token是否为空
|
||||||
String token = request.getHeader("token");
|
|
||||||
if (StringUtils.isBlank(token)) {
|
if (StringUtils.isBlank(token)) {
|
||||||
AjaxResult result = AjaxResult.failed(HttpEnum.TOKEN_EMPTY.getCode(), HttpEnum.TOKEN_EMPTY.getMsg());
|
AjaxResult result = AjaxResult.failed(HttpEnum.TOKEN_EMPTY.getCode(), HttpEnum.TOKEN_EMPTY.getMsg());
|
||||||
response.getWriter().print(JSON.toJSONString(result));
|
response.getWriter().print(JSON.toJSONString(result));
|
||||||
|
|
@ -68,6 +77,8 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
// 用户信息缓存
|
// 用户信息缓存
|
||||||
Object uid = RedisUtil.get(token);
|
Object uid = RedisUtil.get(token);
|
||||||
|
System.out.println(uid);
|
||||||
|
System.out.println("哈哈哈哈哈");
|
||||||
Integer userId = Integer.parseInt(uid.toString());
|
Integer userId = Integer.parseInt(uid.toString());
|
||||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||||
.select("id,sn,username,nickname,mobile,is_disable,is_delete")
|
.select("id,sn,username,nickname,mobile,is_disable,is_delete")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.mdd.front;
|
package com.mdd.front;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class LikeFrontThreadLocal {
|
public class LikeFrontThreadLocal {
|
||||||
|
|
||||||
|
|
@ -31,18 +32,22 @@ public class LikeFrontThreadLocal {
|
||||||
* 获取本地线程
|
* 获取本地线程
|
||||||
*/
|
*/
|
||||||
public static Object get(String key) {
|
public static Object get(String key) {
|
||||||
return MY_LOCAL.get().getOrDefault(key, "");
|
Map<String, Object> map = MY_LOCAL.get();
|
||||||
|
if (map == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return map.getOrDefault(key, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户ID
|
* 获取用户ID
|
||||||
*/
|
*/
|
||||||
public static Integer getUserId() {
|
public static Integer getUserId() {
|
||||||
String adminId = LikeFrontThreadLocal.get("userId").toString();
|
Object adminId = LikeFrontThreadLocal.get("userId");
|
||||||
if (adminId.equals("")) {
|
if (adminId == null || adminId.toString().equals("")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return Integer.parseInt(adminId);
|
return Integer.parseInt(adminId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ public class FrontConfig {
|
||||||
"/api/index",
|
"/api/index",
|
||||||
"/api/config",
|
"/api/config",
|
||||||
"/api/policy",
|
"/api/policy",
|
||||||
|
"/api/search",
|
||||||
"/api/decorate",
|
"/api/decorate",
|
||||||
"/api/sms/send",
|
"/api/sms/send",
|
||||||
|
|
||||||
|
|
@ -22,7 +23,6 @@ public class FrontConfig {
|
||||||
"/api/login/forgotPassword",
|
"/api/login/forgotPassword",
|
||||||
|
|
||||||
"/api/article/category",
|
"/api/article/category",
|
||||||
"/api/article/collect",
|
|
||||||
"/api/article/detail",
|
"/api/article/detail",
|
||||||
"/api/article/list",
|
"/api/article/list",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package com.mdd.front.controller;
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
import com.mdd.common.core.PageResult;
|
import com.mdd.common.core.PageResult;
|
||||||
import com.mdd.common.validator.annotation.IDMust;
|
import com.mdd.common.validator.annotation.IDMust;
|
||||||
|
import com.mdd.front.LikeFrontThreadLocal;
|
||||||
import com.mdd.front.service.IArticleService;
|
import com.mdd.front.service.IArticleService;
|
||||||
import com.mdd.front.validate.PageParam;
|
import com.mdd.front.validate.PageParam;
|
||||||
import com.mdd.front.vo.article.ArticleCateVo;
|
import com.mdd.front.vo.article.ArticleCateVo;
|
||||||
|
|
@ -10,14 +12,15 @@ import com.mdd.front.vo.article.ArticleCollectVo;
|
||||||
import com.mdd.front.vo.article.ArticleDetailVo;
|
import com.mdd.front.vo.article.ArticleDetailVo;
|
||||||
import com.mdd.front.vo.article.ArticleListVo;
|
import com.mdd.front.vo.article.ArticleListVo;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章管理
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/article")
|
@RequestMapping("/api/article")
|
||||||
public class ArticleController {
|
public class ArticleController {
|
||||||
|
|
@ -46,7 +49,8 @@ public class ArticleController {
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Object list(@Validated PageParam pageParam,
|
public Object list(@Validated PageParam pageParam,
|
||||||
@RequestParam(value = "cid", defaultValue = "0") Integer cid) {
|
@RequestParam(value = "cid", defaultValue = "0") Integer cid) {
|
||||||
PageResult<ArticleListVo> list = iArticleService.list(pageParam, cid);
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
|
PageResult<ArticleListVo> list = iArticleService.list(pageParam, cid, userId);
|
||||||
return AjaxResult.success(list);
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +75,42 @@ public class ArticleController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/collect")
|
@GetMapping("/collect")
|
||||||
public Object collect(@Validated PageParam pageParam) {
|
public Object collect(@Validated PageParam pageParam) {
|
||||||
PageResult<ArticleCollectVo> list = iArticleService.collect(pageParam);
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
|
System.out.println(userId);
|
||||||
|
PageResult<ArticleCollectVo> list = iArticleService.collect(pageParam, userId);
|
||||||
return AjaxResult.success(list);
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入收藏
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@PostMapping("/addCollect")
|
||||||
|
public Object addCollect(@RequestBody Map<String, String> params) {
|
||||||
|
Assert.notNull(params.get("articleId"), "articleId参数缺失");
|
||||||
|
Integer articleId = Integer.parseInt(params.get("articleId"));
|
||||||
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
|
iArticleService.addCollect(articleId, userId);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消收藏
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@PostMapping("/cancelCollect")
|
||||||
|
public Object cancelCollect(@RequestBody Map<String, String> params) {
|
||||||
|
Assert.notNull(params.get("id"), "id参数缺失");
|
||||||
|
Integer id = Integer.parseInt(params.get("id"));
|
||||||
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
|
iArticleService.cancelCollect(id, userId);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主页管理
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
public class IndexController {
|
public class IndexController {
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,10 @@ public interface IArticleService {
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param pageParam 分页参数
|
* @param pageParam 分页参数
|
||||||
* @param cid 分类ID
|
* @param cid 分类ID
|
||||||
|
* @param userId 用户ID
|
||||||
* @return PageResult<ArticleListVo>
|
* @return PageResult<ArticleListVo>
|
||||||
*/
|
*/
|
||||||
PageResult<ArticleListVo> list(PageParam pageParam, Integer cid);
|
PageResult<ArticleListVo> list(PageParam pageParam, Integer cid, Integer userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章详情
|
* 文章详情
|
||||||
|
|
@ -46,8 +47,27 @@ public interface IArticleService {
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param pageParam 分页参数
|
* @param pageParam 分页参数
|
||||||
|
* @param userId 用户ID
|
||||||
* @return PageResult<ArticleListVo>
|
* @return PageResult<ArticleListVo>
|
||||||
*/
|
*/
|
||||||
PageResult<ArticleCollectVo> collect(PageParam pageParam);
|
PageResult<ArticleCollectVo> collect(PageParam pageParam, Integer userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入收藏
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param articleId 文章ID
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
void addCollect(Integer articleId, Integer userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消收藏
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 主键
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
void cancelCollect(Integer id, Integer userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,27 @@ package com.mdd.front.service;
|
||||||
import com.mdd.front.vo.user.UserCenterVo;
|
import com.mdd.front.vo.user.UserCenterVo;
|
||||||
import com.mdd.front.vo.user.UserInfoVo;
|
import com.mdd.front.vo.user.UserInfoVo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户服务接口类
|
||||||
|
*/
|
||||||
public interface IUserService {
|
public interface IUserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人中心
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param userId 用户
|
||||||
|
* @return UserCenterVo
|
||||||
|
*/
|
||||||
UserCenterVo center(Integer userId);
|
UserCenterVo center(Integer userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人信息
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return UserInfoVo
|
||||||
|
*/
|
||||||
UserInfoVo info(Integer userId);
|
UserInfoVo info(Integer userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,11 @@ import com.mdd.common.core.PageResult;
|
||||||
import com.mdd.common.entity.article.Article;
|
import com.mdd.common.entity.article.Article;
|
||||||
import com.mdd.common.entity.article.ArticleCategory;
|
import com.mdd.common.entity.article.ArticleCategory;
|
||||||
import com.mdd.common.entity.article.ArticleCollect;
|
import com.mdd.common.entity.article.ArticleCollect;
|
||||||
|
import com.mdd.common.entity.server.Sys;
|
||||||
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
||||||
|
import com.mdd.common.mapper.article.ArticleCollectMapper;
|
||||||
import com.mdd.common.mapper.article.ArticleMapper;
|
import com.mdd.common.mapper.article.ArticleMapper;
|
||||||
|
import com.mdd.common.utils.StringUtil;
|
||||||
import com.mdd.common.utils.TimeUtil;
|
import com.mdd.common.utils.TimeUtil;
|
||||||
import com.mdd.common.utils.UrlUtil;
|
import com.mdd.common.utils.UrlUtil;
|
||||||
import com.mdd.front.service.IArticleService;
|
import com.mdd.front.service.IArticleService;
|
||||||
|
|
@ -20,6 +23,7 @@ import com.mdd.front.vo.article.ArticleCateVo;
|
||||||
import com.mdd.front.vo.article.ArticleCollectVo;
|
import com.mdd.front.vo.article.ArticleCollectVo;
|
||||||
import com.mdd.front.vo.article.ArticleDetailVo;
|
import com.mdd.front.vo.article.ArticleDetailVo;
|
||||||
import com.mdd.front.vo.article.ArticleListVo;
|
import com.mdd.front.vo.article.ArticleListVo;
|
||||||
|
import net.sf.jsqlparser.statement.create.table.Index;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
@ -40,6 +44,9 @@ public class ArticleServiceImpl implements IArticleService {
|
||||||
@Resource
|
@Resource
|
||||||
ArticleCategoryMapper articleCategoryMapper;
|
ArticleCategoryMapper articleCategoryMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ArticleCollectMapper articleCollectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章分类
|
* 文章分类
|
||||||
*
|
*
|
||||||
|
|
@ -71,10 +78,11 @@ public class ArticleServiceImpl implements IArticleService {
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param pageParam 分页参数
|
* @param pageParam 分页参数
|
||||||
* @param cid 分类ID
|
* @param cid 分类ID
|
||||||
|
* @param userId 用户ID
|
||||||
* @return PageResult<ArticleListVo>
|
* @return PageResult<ArticleListVo>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResult<ArticleListVo> list(PageParam pageParam, Integer cid) {
|
public PageResult<ArticleListVo> list(PageParam pageParam, Integer cid, Integer userId) {
|
||||||
Integer pageNo = pageParam.getPageNo();
|
Integer pageNo = pageParam.getPageNo();
|
||||||
Integer pageSize = pageParam.getPageSize();
|
Integer pageSize = pageParam.getPageSize();
|
||||||
|
|
||||||
|
|
@ -86,13 +94,34 @@ public class ArticleServiceImpl implements IArticleService {
|
||||||
|
|
||||||
IPage<Article> iPage = articleMapper.selectPage(new Page<>(pageNo, pageSize), queryWrapper);
|
IPage<Article> iPage = articleMapper.selectPage(new Page<>(pageNo, pageSize), queryWrapper);
|
||||||
|
|
||||||
|
List<Integer> ids = new LinkedList<>();
|
||||||
List<ArticleListVo> list = new LinkedList<>();
|
List<ArticleListVo> list = new LinkedList<>();
|
||||||
for (Article article : iPage.getRecords()) {
|
for (Article article : iPage.getRecords()) {
|
||||||
ArticleListVo vo = new ArticleListVo();
|
ArticleListVo vo = new ArticleListVo();
|
||||||
BeanUtils.copyProperties(article, vo);
|
BeanUtils.copyProperties(article, vo);
|
||||||
|
vo.setCollect(false);
|
||||||
vo.setImage(UrlUtil.toAbsoluteUrl(article.getImage()));
|
vo.setImage(UrlUtil.toAbsoluteUrl(article.getImage()));
|
||||||
vo.setCreateTime(TimeUtil.timestampToDate(article.getCreateTime()));
|
vo.setCreateTime(TimeUtil.timestampToDate(article.getCreateTime()));
|
||||||
list.add(vo);
|
list.add(vo);
|
||||||
|
|
||||||
|
ids.add(article.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userId != null && userId > 0 && ids.size() > 0) {
|
||||||
|
List<ArticleCollect> articleCollects = articleCollectMapper.selectList(
|
||||||
|
new QueryWrapper<ArticleCollect>()
|
||||||
|
.eq("user_id", userId)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.in("article_id", ids));
|
||||||
|
|
||||||
|
List<Integer> collects = new LinkedList<>();
|
||||||
|
for (ArticleCollect c : articleCollects) {
|
||||||
|
collects.add(c.getArticleId());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ArticleListVo vo : list) {
|
||||||
|
vo.setCollect(collects.contains(vo.getId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||||
|
|
@ -123,19 +152,28 @@ public class ArticleServiceImpl implements IArticleService {
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏列表
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param pageParam 分页参数
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return PageResult<ArticleCollectVo>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResult<ArticleCollectVo> collect(PageParam pageParam) {
|
public PageResult<ArticleCollectVo> collect(PageParam pageParam, Integer userId) {
|
||||||
Integer pageNo = pageParam.getPageNo();
|
Integer pageNo = pageParam.getPageNo();
|
||||||
Integer pageSize = pageParam.getPageSize();
|
Integer pageSize = pageParam.getPageSize();
|
||||||
|
|
||||||
MPJQueryWrapper<ArticleCollect> mpjQueryWrapper = new MPJQueryWrapper<>();
|
MPJQueryWrapper<ArticleCollect> mpjQueryWrapper = new MPJQueryWrapper<>();
|
||||||
mpjQueryWrapper.select("t.id,t.article_id,a.title,a.image,a.intro,a.visit,a.create_time")
|
mpjQueryWrapper.select("t.id,t.article_id,a.title,a.image,a.intro,a.visit,a.create_time")
|
||||||
.eq("t.user_id", 1)
|
.eq("t.user_id", userId)
|
||||||
.eq("t.is_delete", 0)
|
.eq("t.is_delete", 0)
|
||||||
|
.eq("a.is_delete", 0)
|
||||||
.orderByDesc("t.id")
|
.orderByDesc("t.id")
|
||||||
.innerJoin("?_article a ON a.id=t.article_id".replace("?_", GlobalConfig.tablePrefix));
|
.innerJoin("?_article a ON a.id=t.article_id".replace("?_", GlobalConfig.tablePrefix));
|
||||||
|
|
||||||
IPage<ArticleCollectVo> iPage = articleMapper.selectJoinPage(
|
IPage<ArticleCollectVo> iPage = articleCollectMapper.selectJoinPage(
|
||||||
new Page<>(pageNo, pageSize),
|
new Page<>(pageNo, pageSize),
|
||||||
ArticleCollectVo.class,
|
ArticleCollectVo.class,
|
||||||
mpjQueryWrapper);
|
mpjQueryWrapper);
|
||||||
|
|
@ -148,4 +186,57 @@ public class ArticleServiceImpl implements IArticleService {
|
||||||
return PageResult.iPageHandle(iPage);
|
return PageResult.iPageHandle(iPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入收藏
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param articleId 主键
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addCollect(Integer articleId, Integer userId) {
|
||||||
|
ArticleCollect articleCollect = articleCollectMapper.selectOne(
|
||||||
|
new QueryWrapper<ArticleCollect>()
|
||||||
|
.eq("article_id", articleId)
|
||||||
|
.eq("user_id", userId)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
if (StringUtil.isNotNull(articleCollect)) {
|
||||||
|
articleCollect.setIsDelete(0);
|
||||||
|
articleCollect.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||||
|
articleCollectMapper.updateById(articleCollect);
|
||||||
|
} else {
|
||||||
|
ArticleCollect model = new ArticleCollect();
|
||||||
|
model.setArticleId(articleId);
|
||||||
|
model.setUserId(userId);
|
||||||
|
model.setIsDelete(0);
|
||||||
|
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||||
|
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||||
|
articleCollectMapper.insert(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消收藏
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 主键
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void cancelCollect(Integer id, Integer userId) {
|
||||||
|
ArticleCollect articleCollect = articleCollectMapper.selectOne(
|
||||||
|
new QueryWrapper<ArticleCollect>()
|
||||||
|
.eq("id", id)
|
||||||
|
.eq("user_id", userId)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Assert.notNull(articleCollect, "收藏不存在!");
|
||||||
|
|
||||||
|
articleCollect.setIsDelete(1);
|
||||||
|
articleCollect.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||||
|
articleCollectMapper.updateById(articleCollect);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
@Resource
|
@Resource
|
||||||
UserAuthMapper userAuthMapper;
|
UserAuthMapper userAuthMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册账号
|
* 注册账号
|
||||||
*
|
*
|
||||||
|
|
@ -64,7 +63,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
user.setUsername(regParam.getUsername());
|
user.setUsername(regParam.getUsername());
|
||||||
user.setPassword(pwd);
|
user.setPassword(pwd);
|
||||||
user.setSalt(salt);
|
user.setSalt(salt);
|
||||||
user.setChannel(0);
|
user.setChannel(regParam.getClient());
|
||||||
user.setCreateTime(System.currentTimeMillis() / 1000);
|
user.setCreateTime(System.currentTimeMillis() / 1000);
|
||||||
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||||
userMapper.insert(user);
|
userMapper.insert(user);
|
||||||
|
|
@ -81,12 +80,11 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
@Transactional
|
@Transactional
|
||||||
public Map<String, Object> mnpLogin(Map<String, String> params) {
|
public Map<String, Object> mnpLogin(Map<String, String> params) {
|
||||||
Assert.notNull(params.get("code"), "code参数缺失!");
|
Assert.notNull(params.get("code"), "code参数缺失!");
|
||||||
String scene = params.get("scene");
|
|
||||||
String code = params.get("code");
|
String code = params.get("code");
|
||||||
String avatarUrl = params.getOrDefault("avatarUrl", "");
|
String avatarUrl = params.getOrDefault("avatarUrl", "");
|
||||||
String nickName = params.getOrDefault("nickName", "");
|
String nickName = params.getOrDefault("nickName", "");
|
||||||
String gender = params.getOrDefault("gender", "0");
|
String gender = params.getOrDefault("gender", "0");
|
||||||
Integer client = ClientEnum.getCodeByType(scene);
|
Integer client = Integer.parseInt(params.getOrDefault("client", "1"));
|
||||||
|
|
||||||
Map<String, String> config = ConfigUtil.get("mp_channel");
|
Map<String, String> config = ConfigUtil.get("mp_channel");
|
||||||
WxMaService wxMaService = new WxMaServiceImpl();
|
WxMaService wxMaService = new WxMaServiceImpl();
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,12 @@ import com.mdd.front.vo.user.UserCenterVo;
|
||||||
import com.mdd.front.vo.user.UserInfoVo;
|
import com.mdd.front.vo.user.UserInfoVo;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户服务实现类
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserServiceImpl implements IUserService {
|
public class UserServiceImpl implements IUserService {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.mdd.front.validate;
|
package com.mdd.front.validate;
|
||||||
|
|
||||||
|
import com.mdd.common.validator.annotation.IntegerContains;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
@ -32,4 +33,9 @@ public class RegParam implements Serializable {
|
||||||
@Length(min = 6, max = 12, message = "密码必须在6~12个字符内")
|
@Length(min = 6, max = 12, message = "密码必须在6~12个字符内")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@NotNull(message = "client参数缺失")
|
||||||
|
@NotEmpty(message = "客户端不能为空")
|
||||||
|
@IntegerContains(values = {1, 2, 3, 4, 5, 6}, message = "不是合法客户端")
|
||||||
|
private Integer client;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ public class ArticleListVo implements Serializable {
|
||||||
private String image;
|
private String image;
|
||||||
private String intro;
|
private String intro;
|
||||||
private Integer visit;
|
private Integer visit;
|
||||||
|
private Boolean collect;
|
||||||
private String createTime;
|
private String createTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue