Skip to content

Commit

Permalink
添加底部展示信息功能
Browse files Browse the repository at this point in the history
  • Loading branch information
TreasureJade committed Dec 20, 2019
1 parent e9910f4 commit 0ceed51
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void configure(HttpSecurity httpSecurity) throws Exception {
.antMatchers("/configuration/ui").permitAll()
.antMatchers("/configuration/security").permitAll()
//配置允许匿名访问的路径
.antMatchers("/anon/*","/article/*").permitAll()
.antMatchers("/anon/*","/article/*","/getMsg").permitAll()
.antMatchers("/article/uploadpic/").permitAll()
// 博客图片地址
.antMatchers("/home/hobo/blog/blog-pic/*").permitAll()
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/swpu/uchain/blog/controller/IndexController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.swpu.uchain.blog.controller;

import com.swpu.uchain.blog.accessctro.RoleContro;
import com.swpu.uchain.blog.enums.RoleEnum;
import com.swpu.uchain.blog.service.VisitorService;
import com.swpu.uchain.blog.util.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author hobo
* @description
*/
@RestController
@CrossOrigin
@Api(tags = "首页显示")
public class IndexController {

@Autowired
private VisitorService visitorService;

@ApiOperation("获取首页底部信息")
@PostMapping("/getMsg")
public Object getMsg() {
return visitorService.getIndexMsg();
}

@RoleContro(role = RoleEnum.ADMIN)
@ApiOperation("/更新底部网站更新时间")
@PostMapping("/updateTime")
public Object updateTime(String date) {
return ResultVOUtil.success(date);
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/swpu/uchain/blog/dao/VisitorMapper.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package com.swpu.uchain.blog.dao;

import com.swpu.uchain.blog.entity.Visitor;
import com.swpu.uchain.blog.vo.IndexMsgVO;

import java.util.List;

public interface VisitorMapper {

int updateByPrimaryKey(Visitor record);

Visitor selectByPage(String page);

int getArticleTotal();

int getTagsTotal();

int getCommentTotal();

int getLeaveMsgTotal();
}
3 changes: 0 additions & 3 deletions src/main/java/com/swpu/uchain/blog/enums/RoleEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@Getter
public enum RoleEnum {
TOURISTS(0, "游客"),
USER(1, "用户"),
ADMIN(2, "管理员"),
;
Expand All @@ -31,15 +30,13 @@ public static String getRole(Integer integer) {
HashMap<Integer, String> hashMap = new HashMap<>();
hashMap.put(ADMIN.getValue(), ADMIN.getRole());
hashMap.put(USER.getValue(), USER.getRole());
hashMap.put(TOURISTS.getValue(), TOURISTS.getRole());
return hashMap.get(integer);
}

public static Integer getValue(String role) {
HashMap<String, Integer> hashMap = new HashMap<>();
hashMap.put(ADMIN.getRole(), ADMIN.getValue());
hashMap.put(USER.getRole(), USER.getValue());
hashMap.put(TOURISTS.getRole(), TOURISTS.getValue());
return hashMap.get(role);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.swpu.uchain.blog.service;

import com.swpu.uchain.blog.vo.ResultVO;

import javax.servlet.http.HttpServletRequest;

/**
Expand All @@ -14,4 +16,6 @@ public interface VisitorService {
*/
void addVisitorNum(HttpServletRequest request);

ResultVO getIndexMsg();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import com.swpu.uchain.blog.redis.key.IpKey;
import com.swpu.uchain.blog.service.VisitorService;
import com.swpu.uchain.blog.util.IpUtil;
import com.swpu.uchain.blog.util.ResultVOUtil;
import com.swpu.uchain.blog.vo.IndexMsgVO;
import com.swpu.uchain.blog.vo.ResultVO;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -38,4 +42,14 @@ public void addVisitorNum(HttpServletRequest request) {

}
}

@Override
public ResultVO getIndexMsg() {
IndexMsgVO vo = new IndexMsgVO();
vo.setArticleTotal(visitorMapper.getArticleTotal());
vo.setCommentTotal(visitorMapper.getCommentTotal());
vo.setLeaveMessageTotal(visitorMapper.getLeaveMsgTotal());
vo.setTagTotal(visitorMapper.getTagsTotal());
return ResultVOUtil.success(vo);
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/swpu/uchain/blog/vo/IndexMsgVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.swpu.uchain.blog.vo;

import lombok.Data;

/**
* @author hobo
* @description
*/
@Data
public class IndexMsgVO {

private int articleTotal;

private int tagTotal;

private int leaveMessageTotal;

private int commentTotal;
}

32 changes: 32 additions & 0 deletions src/main/resources/mappers/VisitorMapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.swpu.uchain.blog.dao.VisitorMapper" >
<resultMap id="BaseResultMap" type="com.swpu.uchain.blog.entity.Visitor" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="page" property="page" jdbcType="VARCHAR" />
<result column="total_num" property="totalNum" jdbcType="BIGINT" />
</resultMap>
<update id="updateByPrimaryKey" parameterType="com.swpu.uchain.blog.entity.Visitor" >
update visitor
set page = #{page,jdbcType=VARCHAR},
total_num = #{totalNum,jdbcType=BIGINT}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPage" resultType="com.swpu.uchain.blog.entity.Visitor">
select id, page, total_num
from visitor
where page=#{page}
</select>
<select id="getArticleTotal" resultType="java.lang.Integer">
select COUNT(*) from article
</select>
<select id="getTagsTotal" resultType="java.lang.Integer">
select COUNT(*) from tags
</select>
<select id="getCommentTotal" resultType="java.lang.Integer">
select COUNT(*) from comment
</select>
<select id="getLeaveMsgTotal" resultType="java.lang.Integer">
select COUNT(*) from leave_message
</select>
</mapper>

0 comments on commit 0ceed51

Please sign in to comment.