Skip to content

Commit

Permalink
修改为 雪花id 加强安全
Browse files Browse the repository at this point in the history
  • Loading branch information
zenofung committed Mar 13, 2022
1 parent 36d89ec commit 94b8954
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public R list(@RequestParam Map<String, Object> params){
*/
@RequestMapping("/info/{id}/{userId}")
//@RequiresPermissions("wine:article:info")
public R info(@PathVariable("id") Integer id,@PathVariable("userId") Integer userId){
public R info(@PathVariable("id") String id,@PathVariable("userId") String userId){
ArticleEntity article = articleService.getByIdAndContent(id,userId);
return R.ok().put("article", article);
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public R update(@RequestBody ArticleEntity article){
*/
@RequestMapping("/delete")
//@RequiresPermissions("${moduleNamez}:article:delete")
public R delete(@RequestBody Integer[] ids){
public R delete(@RequestBody String[] ids){
articleService.removeByIds(Arrays.asList(ids));

return R.ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public R list(@RequestParam Map<String, Object> params){
*/
@RequestMapping("/list/{articleId}")
//@RequiresPermissions("wine:articlepraise:list")
public R list(@PathVariable Integer articleId){
public R list(@PathVariable String articleId){
List<ArticleLabelEntity> articleId1 = articleLabelService.listByArticleId(articleId);
return R.ok().put("art",articleId1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public R update(@RequestBody UserEntity user){
*/
@RequestMapping("/delete")
//@RequiresPermissions("${moduleNamez}:user:delete")
public R delete(@RequestBody Integer[] ids){
public R delete(@RequestBody String[] ids){
userService.removeByIds(Arrays.asList(ids));

return R.ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public R list(@RequestParam Map<String, Object> params){
*/
@RequestMapping("/list/{id}")
//@RequiresPermissions("wine:wine:list")
public R list(@RequestParam Map<String, Object> params,@PathVariable Integer id){
public R list(@RequestParam Map<String, Object> params,@PathVariable String id){
PageUtils page = wineService.queryPage(params,id);

return R.ok().put("page", page);
Expand All @@ -57,7 +57,7 @@ public R list(@RequestParam Map<String, Object> params,@PathVariable Integer id)
*/
@RequestMapping("/info/{id}")
//@RequiresPermissions("wine:wine:info")
public R info(@PathVariable("id") Integer id){
public R info(@PathVariable("id") String id){
WineEntity wine = wineService.getById(id);

return R.ok().put("wine", wine);
Expand Down Expand Up @@ -90,7 +90,7 @@ public R update(@RequestBody WineEntity wine){
*/
@RequestMapping("/delete")
//@RequiresPermissions("${moduleNamez}:wine:delete")
public R delete(@RequestBody Integer[] ids){
public R delete(@RequestBody String[] ids){
wineService.removeByIds(Arrays.asList(ids));

return R.ok();
Expand Down
7 changes: 6 additions & 1 deletion wine/src/main/java/com/wine/game/wine/dao/ArticleDao.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.wine.game.wine.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wine.game.wine.entity.ArticleEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
*
*
Expand All @@ -13,5 +16,7 @@
*/
@Mapper
public interface ArticleDao extends BaseMapper<ArticleEntity> {


IPage<ArticleEntity> findByAttentionID(IPage<?> page,String userId);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wine.game.wine.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
Expand All @@ -25,8 +26,8 @@ public class ArticleEntity implements Serializable {
/**
*
*/
@TableId
private Integer id;
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
*
*/
Expand All @@ -36,7 +37,7 @@ public class ArticleEntity implements Serializable {
*/
private String images;

private Integer userId;
private String userId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ArticleLabelEntity implements Serializable {
/**
*
*/
private Integer articleId;
private String articleId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class ArticlePraiseEntity implements Serializable {
/**
*
*/
private Integer userId;
private String userId;
/**
*
*/
private Integer articleId;
private String articleId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AttentionCommentEntity implements Serializable {
/**
*
*/
private Integer articleId;
private String articleId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class AttentionEntity implements Serializable {
/**
*
*/
private Integer meId;
private String meId;
/**
*
*/
private Integer followerId;
private String followerId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public class ComComEntity implements Serializable {
/**
*
*/
private Integer userId;
private String userId;

/**
*
*/
private Integer userIdTwo;
private String userIdTwo;
/**
*
*/
private Integer comIdTwo;
private String comIdTwo;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ComComPraiseEntity implements Serializable {
/**
*
*/
private Integer userId;
private String userId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class CommentEntity implements Serializable {
/**
*
*/
private Integer userId;
private String userId;
/**
*
*/
private Integer artId;
private String artId;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CommentPraiseEntity implements Serializable {
/**
*
*/
private Integer userId;
private String userId;
/**
*
*/
Expand Down
6 changes: 4 additions & 2 deletions wine/src/main/java/com/wine/game/wine/entity/UserEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wine.game.wine.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

Expand All @@ -22,8 +23,8 @@ public class UserEntity implements Serializable {
/**
*
*/
@TableId
private Integer id;
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
*
*/
Expand Down Expand Up @@ -69,4 +70,5 @@ public class UserEntity implements Serializable {
*/
private Date createTime;


}
5 changes: 3 additions & 2 deletions wine/src/main/java/com/wine/game/wine/entity/WineEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wine.game.wine.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

Expand All @@ -22,8 +23,8 @@ public class WineEntity implements Serializable {
/**
*
*/
@TableId
private Integer id;
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ArticleLabelService extends IService<ArticleLabelEntity> {

PageUtils queryPage(Map<String, Object> params);

List<ArticleLabelEntity> listByArticleId(Integer articleId);
List<ArticleLabelEntity> listByArticleId(String articleId);

}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public interface ArticleService extends IService<ArticleEntity> {

PageUtils queryPage(Map<String, Object> params);

ArticleEntity getByIdAndContent(Integer id,Integer userId);
ArticleEntity getByIdAndContent(String id,String userId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public interface WineService extends IService<WineEntity> {

PageUtils queryPage(Map<String, Object> params);

PageUtils queryPage(Map<String, Object> params, Integer id);
PageUtils queryPage(Map<String, Object> params, String id);
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PageUtils queryPage(Map<String, Object> params) {
}

@Override
public List<ArticleLabelEntity> listByArticleId(Integer articleId) {
public List<ArticleLabelEntity> listByArticleId(String articleId) {
List<ArticleLabelEntity> article_id = this.list(new QueryWrapper<ArticleLabelEntity>().eq("article_id", articleId));
article_id.stream().forEach(m->{
m.setLabelEntity(labelService.getById(m.getLabelId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ public PageUtils queryPage(Map<String, Object> params) {
if (StringUtils.isEmpty(params.get("user_id"))){
new TimeoutException("没有用户id");
}
IPage<ArticleEntity> page = this.page(
new Query<ArticleEntity>().getPage(params),
new QueryWrapper<ArticleEntity>()
);
IPage<ArticleEntity> page = null;
if (StringUtils.isEmpty(params.get("attention"))){
page = this.page(
new Query<ArticleEntity>().getPage(params),
new QueryWrapper<ArticleEntity>()
);
}else {
page= articleDao.findByAttentionID(new Query<ArticleEntity>().getPage(params),params.get("user_id").toString());
}
getPageArticle(params, page);
return new PageUtils(page);
}

private void getPageArticle(Map<String, Object> params, IPage<ArticleEntity> page) {
page.getRecords().stream().forEach(m -> {
QueryWrapper<CommentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("art_id", m.getId());
Expand All @@ -71,23 +81,20 @@ public PageUtils queryPage(Map<String, Object> params) {
m.setPraises(articleId.size());
List<ArticlePraiseEntity> articleId2 = articlePraiseService.list(new QueryWrapper<ArticlePraiseEntity>().eq("article_id", m.getId()).eq("user_id", params.get("user_id")));
m.setPraiseStatus(articleId2.size() > 0 ? true : false);
//TODO 获取是否关注
// 获取是否关注
// attentionService
List<AttentionEntity> list1 = attentionService.list(new QueryWrapper<AttentionEntity>().eq("me_id", params.get("user_id")).eq("follower_id",m.getUserId()));
m.setAttentionStatus(list1.size() > 0 ? true:false);


//标签
m.setLabelEntities(articleLabelService.listByArticleId(m.getId()));
//获取酒局
m.setWineEntity(wineService.getById(m.getWineId()));

});
return new PageUtils(page);
}

@Override
public ArticleEntity getByIdAndContent(Integer id, Integer userId) {
public ArticleEntity getByIdAndContent(String id, String userId) {
ArticleEntity articleEntity = articleDao.selectById(id);
UserEntity byId = userService.getById(articleEntity.getUserId());
articleEntity.setUserEntity(byId);
Expand Down Expand Up @@ -120,7 +127,7 @@ public ArticleEntity getByIdAndContent(Integer id, Integer userId) {
return articleEntity;
}

public void getListComCom(List<ComComEntity> comComEntityList, Integer userId) {
public void getListComCom(List<ComComEntity> comComEntityList, String userId) {
// List<ComComEntity> =new ArrayList<>();

for (ComComEntity co : comComEntityList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PageUtils queryPage(Map<String, Object> params) {
}

@Override
public PageUtils queryPage(Map<String, Object> params, Integer id) {
public PageUtils queryPage(Map<String, Object> params, String id) {
QueryWrapper<WineEntity> wineEntityQueryWrapper = new QueryWrapper<>();
if (!StringUtils.isEmpty(id)){
wineEntityQueryWrapper.eq("id",id);
Expand Down
4 changes: 4 additions & 0 deletions wine/src/main/resources/mapper/wine/ArticleDao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<result property="updateTime" column="update_time"/>
<result property="createTime" column="create_time"/>
</resultMap>
<select id="findByAttentionID" resultType="com.wine.game.wine.entity.ArticleEntity">
SELECT war.* from w_attention as watt left join w_article as war on watt.follower_id=war.user_id
WHERE watt.me_id=#{userId} and war.id is not NULL
</select>


</mapper>

0 comments on commit 94b8954

Please sign in to comment.