后台首页面板数据接口&代码优化

This commit is contained in:
linfeng 2022-04-23 20:22:43 +08:00
parent 1a0645a72d
commit e5f4a6ad14
19 changed files with 135 additions and 80 deletions

18
.gitignore vendored
View File

@ -23,3 +23,21 @@ target
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
.DS_Store
node_modules/
dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/test/unit/coverage/
/test/e2e/reports/
selenium-debug.log
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln

View File

@ -8,34 +8,33 @@ import lombok.experimental.Accessors;
import java.io.Serializable; import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/** /**
* 主页统计数据对象 * 面板统计数据对象
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) @Accessors(chain = true)
@ApiModel(value="HomeRateResponse对象", description="主页统计数据对象") @ApiModel(value="HomeRateResponse对象", description="面板统计数据对象")
public class HomeRateResponse implements Serializable { public class HomeRateResponse implements Serializable {
private static final long serialVersionUID=1L; private static final long serialVersionUID=1L;
@ApiModelProperty(value = "今日销售额") @ApiModelProperty(value = "总用户数")
private Object sales; private Object totalUser;
@ApiModelProperty(value = "昨日销售额") @ApiModelProperty(value = "总帖子数")
private Object yesterdaySales; private Object totalPost;
@ApiModelProperty(value = "今日访问量") @ApiModelProperty(value = "总待审核帖子数")
private Object pageviews; private Object totalPostOfReview;
@ApiModelProperty(value = "昨日访问量")
private Object yesterdayPageviews;
@ApiModelProperty(value = "今日订单量")
private Object orderNum;
@ApiModelProperty(value = "昨日订单量")
private Object yesterdayOrderNum;
@ApiModelProperty(value = "今日新增用户") @ApiModelProperty(value = "今日新增用户")
private Object newUserNum; private Object newUserNum;

View File

@ -1,12 +1,15 @@
package io.linfeng.modules.admin.controller; package io.linfeng.modules.admin.controller;
import io.linfeng.common.utils.R; import io.linfeng.common.utils.R;
import io.linfeng.modules.admin.service.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* 后台前端首页数据统计 * 后台前端首页数据统计
*
* @author linfeng * @author linfeng
* @date 2022/4/17 16:49 * @date 2022/4/17 16:49
*/ */
@ -14,9 +17,13 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("admin/statistics") @RequestMapping("admin/statistics")
public class StatisticController { public class StatisticController {
@GetMapping("/home") @Autowired
public R index(){ private AppUserService userService;
return R.ok();
@GetMapping("/home")
public R index() {
return R.ok().put("result", userService.indexDate());
} }
} }

View File

@ -3,6 +3,7 @@ package io.linfeng.modules.admin.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import io.linfeng.common.response.AppUserInfoResponse; import io.linfeng.common.response.AppUserInfoResponse;
import io.linfeng.common.response.AppUserResponse; import io.linfeng.common.response.AppUserResponse;
import io.linfeng.common.response.HomeRateResponse;
import io.linfeng.common.utils.AppPageUtils; import io.linfeng.common.utils.AppPageUtils;
import io.linfeng.common.utils.PageUtils; import io.linfeng.common.utils.PageUtils;
import io.linfeng.modules.admin.entity.AppUserEntity; import io.linfeng.modules.admin.entity.AppUserEntity;
@ -27,5 +28,11 @@ public interface AppUserService extends IService<AppUserEntity> {
void ban(Integer id); void ban(Integer id);
void openBan(Integer id); void openBan(Integer id);
/**
* 首页数据
* @return HomeRateResponse
*/
HomeRateResponse indexDate();
} }

View File

@ -1,9 +1,12 @@
package io.linfeng.modules.admin.service.impl; package io.linfeng.modules.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.linfeng.common.exception.LinfengException; import io.linfeng.common.exception.LinfengException;
import io.linfeng.common.response.HomeRateResponse;
import io.linfeng.common.utils.*; import io.linfeng.common.utils.*;
import io.linfeng.modules.admin.entity.PostEntity;
import io.linfeng.modules.admin.service.*; import io.linfeng.modules.admin.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -17,11 +20,20 @@ import io.linfeng.modules.admin.entity.AppUserEntity;
public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> implements AppUserService { public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> implements AppUserService {
@Autowired
private PostService postService;
@Autowired
private AppUserDao userDao;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<AppUserEntity> queryWrapper=new QueryWrapper<>();
queryWrapper.lambda().orderByDesc(AppUserEntity::getUid);
IPage<AppUserEntity> page = this.page( IPage<AppUserEntity> page = this.page(
new Query<AppUserEntity>().getPage(params), new Query<AppUserEntity>().getPage(params),
new QueryWrapper<>() queryWrapper
); );
return new PageUtils(page); return new PageUtils(page);
@ -34,10 +46,10 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
if(status==1){ if(status==1){
throw new LinfengException("该用户已被禁用"); throw new LinfengException("该用户已被禁用");
} }
UpdateWrapper<AppUserEntity> updateWrapper = new UpdateWrapper<>(); this.lambdaUpdate()
updateWrapper.set("status",1); .set(AppUserEntity::getStatus,1)
updateWrapper.eq("uid",id); .eq(AppUserEntity::getUid,id)
update(updateWrapper); .update();
} }
@Override @Override
@ -46,11 +58,36 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserDao, AppUserEntity> i
if(status==0){ if(status==0){
throw new LinfengException("该用户已解除禁用"); throw new LinfengException("该用户已解除禁用");
} }
UpdateWrapper<AppUserEntity> updateWrapper = new UpdateWrapper<>(); this.lambdaUpdate()
updateWrapper.set("status",0); .set(AppUserEntity::getStatus,0)
updateWrapper.eq("uid",id); .eq(AppUserEntity::getUid,id)
update(updateWrapper); .update();
} }
@Override
public HomeRateResponse indexDate() {
String today = cn.hutool.core.date.DateUtil.date().toString("yyyy-MM-dd");
String yesterday = cn.hutool.core.date.DateUtil.yesterday().toString("yyyy-MM-dd");
// Integer count = postService.lambdaQuery().eq(PostEntity::getStatus, Constant.POST_REVIEWED).count();
Integer postCount = postService.lambdaQuery().select(PostEntity::getId).count();
HomeRateResponse response = new HomeRateResponse();
response.setTotalPostOfReview(0);
response.setTotalPost(postCount);
response.setNewUserNum(this.getRegisterNumByDate(today));
response.setYesterdayNewUserNum(this.getRegisterNumByDate(yesterday));
response.setTotalUser(this.getTotalNum());
return response;
}
private Integer getTotalNum() {
return this.lambdaQuery().select(AppUserEntity::getUid).count();
}
private Integer getRegisterNumByDate(String date) {
QueryWrapper<AppUserEntity> wrapper = Wrappers.query();
wrapper.select("uid");
wrapper.apply("date_format(create_time, '%Y-%m-%d') = {0}", date);
return userDao.selectCount(wrapper);
}
} }

View File

@ -34,19 +34,16 @@ public class CommentServiceImpl extends ServiceImpl<CommentDao, CommentEntity> i
@Override @Override
public Integer getCountByTopicId(Integer id) { public Integer getCountByTopicId(Integer id) {
Integer count = baseMapper.selectCount(new LambdaQueryWrapper<CommentEntity>() return baseMapper.selectCount(new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getStatus,1) .eq(CommentEntity::getStatus,1)
.eq(CommentEntity::getPostId, id)); .eq(CommentEntity::getPostId, id));
return count;
} }
@Override @Override
public List<CommentEntity> getByPid(Long pid) { public List<CommentEntity> getByPid(Long pid) {
List<CommentEntity> commentList = baseMapper.selectList( return baseMapper.selectList(
new LambdaQueryWrapper<CommentEntity>() new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getPid, pid)); .eq(CommentEntity::getPid, pid));
return commentList;
} }

View File

@ -86,14 +86,12 @@ public class MessageServiceImpl extends ServiceImpl<MessageDao, MessageEntity> i
@Override @Override
public Boolean status(Integer type, Integer uid) { public Boolean status(Integer type, Integer uid) {
List<Integer> list = new ArrayList<>();
list.add(Constant.STAR);
list.add(Constant.COLLECT);
UpdateWrapper<MessageEntity> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<MessageEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("status",1); updateWrapper.set("status",1);
updateWrapper.eq("to_uid",uid); updateWrapper.eq("to_uid",uid);
if(type==1){ if(type==1){
updateWrapper.in("type",list); updateWrapper.and(wrapper->wrapper.eq("type",Constant.STAR).or().eq("type",Constant.COLLECT));
}else if(type==2){ }else if(type==2){
updateWrapper.eq("type",Constant.WATCH); updateWrapper.eq("type",Constant.WATCH);
}else if(type==3){ }else if(type==3){

View File

@ -85,8 +85,7 @@ public class PostServiceImpl extends ServiceImpl<PostDao, PostEntity> implements
public Integer findTopicPostCount(Integer topicId) { public Integer findTopicPostCount(Integer topicId) {
LambdaQueryWrapper<PostEntity> lambdaQueryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<PostEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(PostEntity::getTopicId,topicId); lambdaQueryWrapper.eq(PostEntity::getTopicId,topicId);
Integer num = baseMapper.selectCount(lambdaQueryWrapper); return baseMapper.selectCount(lambdaQueryWrapper);
return num;
} }
/** /**
@ -96,26 +95,29 @@ public class PostServiceImpl extends ServiceImpl<PostDao, PostEntity> implements
*/ */
@Override @Override
public List<String> findThreeMedia(Integer id) { public List<String> findThreeMedia(Integer id) {
QueryWrapper<PostEntity> queryWrapper=new QueryWrapper(); QueryWrapper<PostEntity> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("topic_id",id); queryWrapper.eq("topic_id",id);
queryWrapper.eq("type",1); queryWrapper.eq("type",1);
queryWrapper.orderByDesc("read_count"); queryWrapper.orderByDesc("read_count");
queryWrapper.last("limit 3"); queryWrapper.last("limit 10");
List<PostEntity> postEntityList = baseMapper.selectList(queryWrapper); List<PostEntity> postEntityList = baseMapper.selectList(queryWrapper);
List<String> imageList=new ArrayList<>(); List<String> imageList=new ArrayList<>();
postEntityList.forEach(list->{ for (int i = 0; i < postEntityList.size() ; i++) {
if(!list.getMedia().equals("")){ if(!postEntityList.get(i).getMedia().equals("")){
List<String> jsonToList = JsonUtils.JsonToList(list.getMedia()); List<String> jsonToList = JsonUtils.JsonToList(postEntityList.get(i).getMedia());
if(jsonToList.size()>0){ if(jsonToList.size()>0){
imageList.add(jsonToList.get(0)); if(imageList.size()>2){
break;
}else{
imageList.add(jsonToList.get(0));
}
} }
} }
}); }
return imageList; return imageList;
} }
@Override @Override
@Transactional @Transactional
public void deleteByAdmin(List<Integer> ids) { public void deleteByAdmin(List<Integer> ids) {

View File

@ -17,14 +17,12 @@ import io.linfeng.modules.admin.service.SystemService;
@Service("systemService") @Service("systemService")
public class SystemServiceImpl extends ServiceImpl<SystemDao, SystemEntity> implements SystemService { public class SystemServiceImpl extends ServiceImpl<SystemDao, SystemEntity> implements SystemService {
@Autowired
private AppUserDao appUserDao;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<SystemEntity> page = this.page( IPage<SystemEntity> page = this.page(
new Query<SystemEntity>().getPage(params), new Query<SystemEntity>().getPage(params),
new QueryWrapper<SystemEntity>() new QueryWrapper<>()
); );
return new PageUtils(page); return new PageUtils(page);

View File

@ -35,7 +35,7 @@ public class TopicServiceImpl extends ServiceImpl<TopicDao, TopicEntity> impleme
public AppPageUtils queryByPage(Map<String, Object> params) { public AppPageUtils queryByPage(Map<String, Object> params) {
Integer classId = Integer.valueOf((String) params.get(Constant.CLASSID)); Integer classId = Integer.valueOf((String) params.get(Constant.CLASSID));
QueryWrapper<TopicEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<TopicEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("cate_id", classId); queryWrapper.lambda().eq(TopicEntity::getCateId, classId);
IPage<TopicEntity> page = this.page( IPage<TopicEntity> page = this.page(
new Query<TopicEntity>().getPage(params), new Query<TopicEntity>().getPage(params),

View File

@ -27,7 +27,7 @@ public class PostCollectionServiceImpl extends ServiceImpl<PostCollectionDao, Po
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<PostCollectionEntity> page = this.page( IPage<PostCollectionEntity> page = this.page(
new Query<PostCollectionEntity>().getPage(params), new Query<PostCollectionEntity>().getPage(params),
new QueryWrapper<PostCollectionEntity>() new QueryWrapper<>()
); );
return new PageUtils(page); return new PageUtils(page);
@ -35,10 +35,9 @@ public class PostCollectionServiceImpl extends ServiceImpl<PostCollectionDao, Po
@Override @Override
public Integer collectCount(Integer postId) { public Integer collectCount(Integer postId) {
Integer count = baseMapper.selectCount(new LambdaQueryWrapper<PostCollectionEntity>()
.eq(PostCollectionEntity::getPostId, postId));
return count; return baseMapper.selectCount(new LambdaQueryWrapper<PostCollectionEntity>()
.eq(PostCollectionEntity::getPostId, postId));
} }
@Override @Override
@ -47,10 +46,7 @@ public class PostCollectionServiceImpl extends ServiceImpl<PostCollectionDao, Po
new LambdaQueryWrapper<PostCollectionEntity>() new LambdaQueryWrapper<PostCollectionEntity>()
.eq(PostCollectionEntity::getPostId, postId) .eq(PostCollectionEntity::getPostId, postId)
.eq(PostCollectionEntity::getUid, uid)); .eq(PostCollectionEntity::getUid, uid));
if(entity!=null){ return entity != null;
return true;
}
return false;
} }
@Override @Override
@ -66,8 +62,7 @@ public class PostCollectionServiceImpl extends ServiceImpl<PostCollectionDao, Po
lambdaQueryWrapper.select(PostCollectionEntity::getPostId); lambdaQueryWrapper.select(PostCollectionEntity::getPostId);
lambdaQueryWrapper.in(PostCollectionEntity::getUid, uid); lambdaQueryWrapper.in(PostCollectionEntity::getUid, uid);
List<PostCollectionEntity> postCollectionEntities = baseMapper.selectList(lambdaQueryWrapper); List<PostCollectionEntity> postCollectionEntities = baseMapper.selectList(lambdaQueryWrapper);
List<Integer> collect = postCollectionEntities.stream().map(PostCollectionEntity::getPostId).collect(Collectors.toList()); return postCollectionEntities.stream().map(PostCollectionEntity::getPostId).collect(Collectors.toList());
return collect;
} }
} }

View File

@ -33,10 +33,7 @@ public class PostFabulousServiceImpl extends ServiceImpl<PostFabulousDao, PostFa
new LambdaQueryWrapper<PostFabulousEntity>() new LambdaQueryWrapper<PostFabulousEntity>()
.eq(PostFabulousEntity::getPostId, id) .eq(PostFabulousEntity::getPostId, id)
.eq(PostFabulousEntity::getUid, uid)); .eq(PostFabulousEntity::getUid, uid));
if(entity!=null){ return entity != null;
return true;
}
return false;
} }
} }

View File

@ -22,7 +22,7 @@ public class TopicAdminServiceImpl extends ServiceImpl<TopicAdminDao, TopicAdmin
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<TopicAdminEntity> page = this.page( IPage<TopicAdminEntity> page = this.page(
new Query<TopicAdminEntity>().getPage(params), new Query<TopicAdminEntity>().getPage(params),
new QueryWrapper<TopicAdminEntity>() new QueryWrapper<>()
); );
return new PageUtils(page); return new PageUtils(page);

View File

@ -25,7 +25,7 @@ public class TopicTopServiceImpl extends ServiceImpl<TopicTopDao, TopicTopEntity
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<TopicTopEntity> page = this.page( IPage<TopicTopEntity> page = this.page(
new Query<TopicTopEntity>().getPage(params), new Query<TopicTopEntity>().getPage(params),
new QueryWrapper<TopicTopEntity>() new QueryWrapper<>()
); );
return new PageUtils(page); return new PageUtils(page);
@ -35,8 +35,7 @@ public class TopicTopServiceImpl extends ServiceImpl<TopicTopDao, TopicTopEntity
public List<TopicTopEntity> findByTopicId(Integer topicId) { public List<TopicTopEntity> findByTopicId(Integer topicId) {
LambdaQueryWrapper<TopicTopEntity> lambdaQueryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<TopicTopEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(TopicTopEntity::getTopicId, topicId); lambdaQueryWrapper.eq(TopicTopEntity::getTopicId, topicId);
List<TopicTopEntity> list = baseMapper.selectList(lambdaQueryWrapper); return baseMapper.selectList(lambdaQueryWrapper);
return list;
} }
} }

View File

@ -21,7 +21,7 @@ public class UserTopicServiceImpl extends ServiceImpl<UserTopicDao, UserTopicEnt
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<UserTopicEntity> page = this.page( IPage<UserTopicEntity> page = this.page(
new Query<UserTopicEntity>().getPage(params), new Query<UserTopicEntity>().getPage(params),
new QueryWrapper<UserTopicEntity>() new QueryWrapper<>()
); );
return new PageUtils(page); return new PageUtils(page);

View File

@ -1,5 +1,6 @@
==================================================================================================================== ===================================================================================================================================
欢迎使用林风科技_社交圈子app后端api 欢迎使用林风社交论坛项目后端api
https://www.linfeng.tech
==================================================================================================================== ===================================================================================================================================

View File

@ -1,5 +1,5 @@
{ {
"name": "linfengCommunity-vue", "name": "linfeng-community-vue",
"version": "1.2.2", "version": "1.2.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,

View File

@ -2,12 +2,12 @@
<div class="mod-home"> <div class="mod-home">
<h2>数据概览</h2> <h2>数据概览</h2>
<h4> <!-- <h4>
林风社交圈子是基于Springboot MybatisPlus Shiro Jwt Vue Uniapp Redis 林风社交圈子是基于Springboot MybatisPlus Shiro Jwt Vue Uniapp Redis
MySQL构建的社交app平台 MySQL构建的社交app平台
</h4> </h4> -->
<!--头部--> <!--头部-->
<!-- <base-info ref="baseInfo"/> --> <base-info ref="baseInfo"/>
</div> </div>
</template> </template>

View File

@ -163,7 +163,7 @@
<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.uid)">修改</el-button> <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.uid)">修改</el-button>
<el-button v-if="scope.row.status == 0" type="text" size="small" @click="banHandle(scope.row.uid)">禁用</el-button> <el-button v-if="scope.row.status == 0" type="text" size="small" @click="banHandle(scope.row.uid)">禁用</el-button>
<el-button v-if="scope.row.status == 1" type="text" size="small" @click="openBanHandle(scope.row.uid)">解禁</el-button> <el-button v-if="scope.row.status == 1" type="text" size="small" @click="openBanHandle(scope.row.uid)">解禁</el-button>
<el-button type="text" size="small" @click="deleteHandle(scope.row.uid)">删除</el-button> <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.uid)">删除</el-button> -->
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>