Compare commits

..

12 Commits

@ -0,0 +1,3 @@
# pyx_gitkeshe
本人主要负责软件需求文档编写和后端代码编写。

@ -14,7 +14,7 @@ import java.util.List;
@Component
//重点
@WebFilter({"/user/*","/api","/upload","/borrow","/api/rank"})
@WebFilter({"/user/*","/api","/upload","/borrow"})
public class MyFilter implements Filter{
List<String> exclude;

@ -1,12 +1,10 @@
package com.example.demo.controller;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.Article;
import com.example.demo.pojo.Result;
import com.example.demo.service.ArticleService;
import com.fasterxml.jackson.core.JsonProcessingException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -21,20 +19,11 @@ public class ArticleController {
@Autowired
ArticleService articleService;
@Autowired
UserMapper userMapper;
@PostMapping("/add")
public Result<Article> addarticle(@RequestBody Article article, HttpSession session) throws JsonProcessingException {
public Result<Article> addarticle(@RequestBody Article article) throws JsonProcessingException {
System.out.println("Received article: " + article); // 添加此行以调试
int admin = userMapper.findByUserName(String.valueOf(session.getAttribute("username"))).getAdmin();
if (admin == 1) {
articleService.addarticle(article);
return Result.success(article);
}
else{
return Result.error("权限不够。。。");
}
articleService.addarticle(article);
return Result.success(article);
}
@GetMapping("/select")
@ -44,7 +33,15 @@ public class ArticleController {
return Result.success(articles);
}
@DeleteMapping("/delete/{id}")
public Result deleteArticle(@PathVariable Long id) {
boolean deleted = articleService.deletearticle(id);
if (deleted) {
return Result.success();
} else {
return Result.error("删除失败!");
}
}
//根据书籍名字搜索单个书籍信息
@GetMapping("/selectone")

@ -0,0 +1,35 @@
package com.example.demo.controller;
import com.example.demo.pojo.Borrow;
import com.example.demo.pojo.Result;
import com.example.demo.service.BorrowService;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpSession;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin
@RequestMapping("/borrow")
public class BorrowController {
@Autowired
private BorrowService borrowService;
//租借书
@PostMapping("/borrowbook")
public Result borrowbook(String title, HttpSession session){
Borrow borrow=new Borrow();
borrow.setTitle(title);
borrow.setBorrower((String) session.getAttribute("username"));
borrowService.borrow(borrow);
return Result.success(borrow);
}
}

@ -1,20 +1,17 @@
package com.example.demo.controller;
import com.example.demo.mapper.BorrowMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.*;
import com.example.demo.service.ArticleService;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.User;
import com.example.demo.pojo.info;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@CrossOrigin(origins = "http://localhost:8877")
@RestController
@ -27,12 +24,6 @@ public class UserController {
@Autowired
private UserMapper userMapper;
@Autowired
private BorrowMapper borrowMapper;
@Autowired
private ArticleService articleService;
//获取用户登陆信息
@GetMapping("/getinfo")
public ResponseEntity<?> getInfo(HttpSession session) {
@ -87,45 +78,10 @@ public class UserController {
return Result.success("成功充值:"+money+"元");
}
//查询金额+VIP
@PostMapping("/findmoney")
@GetMapping("/findmoney")
public Result findmoney(HttpSession session){
float balance=userService.findmoney(session.getAttribute("username"));
userMapper.updateVIP(balance,(String) session.getAttribute("username"));
int VIP=userMapper.findVIP((String) session.getAttribute("username"));
return Result.success("余额为:"+balance+"元"+" 当前VIP等级为"+VIP);
}
//查询个人借书记录
@GetMapping("findone")
public Result findone(HttpSession session){
User user=userMapper.findByUserName((String) session.getAttribute("username"));
int admin=user.getAdmin();
if(admin==1){
List<Borrow> borrow=borrowMapper.findall();
return Result.success(borrow);
}
else{
Borrow borrow=borrowMapper.findone(user.getUsername());
return Result.success(borrow);
}
float money=userService.findmoney(session.getAttribute("username"));
return Result.success("余额为:"+money+"元");
}
//管理员删除书籍
@PostMapping("delete")
public Result delete(String title,HttpSession session) {
int admin = userMapper.findByUserName((String) session.getAttribute("username")).getAdmin();
if (admin == 1) {
userMapper.deletebook(title);
return Result.success("该书本已删除!");
}
else{
return Result.error("权限不够。。。");
}
}
@GetMapping("/borrow/books")
public Result<List<Article>> getUserBorrowedBooks(HttpSession session) {
return Result.success(articleService.getUserBorrowedBooks((String) session.getAttribute("username")));
}
}

@ -20,23 +20,11 @@ public interface ArticleMapper {
@Select("SELECT * FROM article")
List<Article> selectarticle();
//查询
//管理员删除书籍
@Delete("DELETE FROM article WHERE id = #{id}")
Integer deleteArticle(Long id);
//查询单本书
@Select("SELECT * from article where title=#{title}")
Article selectonearticle(String title);
@Select("SELECT a.* " +
"FROM article a " +
"INNER JOIN borrow b ON a.title = b.title " +
"INNER JOIN user u ON b.borrower = u.username " +
"WHERE u.username = #{username} " +
"AND b.borrow_time IS NOT NULL " +
"AND b.return_time IS NULL")
List<Article> findBorrowedBooksByUsername(String username);
}

@ -0,0 +1,20 @@
package com.example.demo.mapper;
import com.example.demo.pojo.Borrow;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BorrowMapper {
@Insert("INSERT INTO borrow (title, borrower, borrow_time)\n" +
"VALUES \n" +
"(#{title}, #{borrower}, now())")
void borrowrecord(Borrow borrow);
@Insert("INSERT INTO borrow (title, borrower, return_time)\n" +
"VALUES \n" +
"(#{title}, #{borrower}, now())")
void returnrecord(Borrow borrow);
}

@ -0,0 +1,36 @@
package com.example.demo.mapper;
import com.example.demo.pojo.User;
import com.example.demo.pojo.info;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface UserMapper {
@Select("select * from user where username=#{username}")
User findByUserName(String username);
@Insert("insert into user(username,password,vip,create_time,update_time,admin,balance)" +
" values(#{username},#{password},#{vip},now(),now(),#{admin},#{balance})")
void add(String username,String password,int vip,int admin,float balance);
@Select("SELECT password FROM user WHERE username=#{username}")
String login(String username);
@Select("select username,pic from user where username=#{username}")
info getinfo( String username);
//充钱
@Update("UPDATE user\n" +
"SET balance=balance+#{money1}\n" +
"WHERE username=#{username};")
void recharge(float money1,String username);
@Select("select balance from user where username=#{username}")
float findbalance(Object username);
}

@ -10,6 +10,4 @@ public class Article {
private String content;
private String url;
private String state;
private float money;
private int number;
}

@ -8,6 +8,6 @@ import java.time.LocalDateTime;
public class Borrow {
private String title;
private String borrower;
private LocalDateTime borrow_time;
private LocalDateTime return_time;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}

@ -9,8 +9,6 @@ public interface ArticleService {
List<Article> selectarticle();
List<Article> getUserBorrowedBooks(String username);
boolean deletearticle(Long id);
Article selectonearticle(String title);

@ -15,6 +15,4 @@ public interface UserService {
void recharge(float money, String username);
float findmoney(Object username);
void deduct(float money, Object username);
}

@ -35,13 +35,4 @@ public class ArticleServiceImpl implements ArticleService {
public Article selectonearticle(String title) {
return articleMapper.selectonearticle(title);
}
@Override
public List<Article> getUserBorrowedBooks(String username) {
// 可添加参数校验(如用户名非空)
if (username == null || username.trim().isEmpty()) {
throw new IllegalArgumentException("用户名不能为空");
}
return articleMapper.findBorrowedBooksByUsername(username);
}
}

@ -7,7 +7,6 @@ import com.example.demo.pojo.Borrow;
import com.example.demo.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -17,18 +16,9 @@ public class BorrowServiceImpl implements BorrowService {
@Autowired
BorrowMapper borrowMapper ;
@Transactional
@Override
public void borrow(Borrow borrow) {
// 1. 新增租借记录
borrowMapper.borrowrecord(borrow);
// 2. 对应物品的number+1根据title关联
borrowMapper.incrementArticleNumber(borrow.getTitle());
}
@Override
public void returnbook(Borrow borrow) {
borrowMapper.returnrecord(borrow);
}

@ -50,9 +50,4 @@ public class UserServiceImpl implements UserService {
return userMapper.findbalance(username);
}
@Override
public void deduct(float money,Object name) {
userMapper.deduct(money, (String) name);
}
}

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before

Width:  |  Height:  |  Size: 496 B

After

Width:  |  Height:  |  Size: 496 B

@ -109,8 +109,8 @@ async function fetchUserInfo() {
const vip = computed(() => store.state.vipLevel)
const balance = computed(() => store.state.balance)
const user = computed(() => store.state.user)
console.log("user.pic:"+user.pic)
const user = computed(() => store.state.user)

@ -14,18 +14,14 @@ export default createStore({
isAdmin: state => state.user?.admin || false
},
mutations: {
setUser(state, user) {
const admin = user.admin === 1;
const userData = {
...user,
admin
};
setUser(state, user) {
const admin = user.admin === 1;
const userData = {
...user,
admin
};
state.user = user
console.log("user")
console.log(user)
console.log("state.user")
console.log(state.user)
sessionStorage.setItem('user', JSON.stringify(user))
},
setBalanceAndVip(state, { balance, vip }) {
@ -123,10 +119,7 @@ export default createStore({
// 获取当前用户信息 - 符合接口文档
async fetchUser({ commit, dispatch }) {
try {
const response = await service.get('/user/getinfo')
const userData = response.data
console.log("fetchUer userData")
console.log(userData)
const userData = await service.get('/user/getinfo')
const admin = userData.admin === 1;
// 用户信息接口直接返回用户对象
commit('setUser', {
@ -137,16 +130,16 @@ export default createStore({
// 获取关联信息
try {
await dispatch('fetchBalanceAndVip')
} catch (balanceError) {
console.error('获取余额信息失败:', balanceError)
}
try {
await dispatch('fetchBorrowedBooks')
} catch (booksError) {
console.error('获取借阅书籍失败:', booksError)
}
await dispatch('fetchBalanceAndVip')
} catch (balanceError) {
console.error('获取余额信息失败:', balanceError)
}
try {
await dispatch('fetchBorrowedBooks')
} catch (booksError) {
console.error('获取借阅书籍失败:', booksError)
}
return userData
} catch (error) {
@ -160,18 +153,16 @@ export default createStore({
try {
const response = await service.post('/user/findmoney')
const resData = response.data || {}
if (resData.code === 200) {
console.log("fetchBalanceAndVip resData")
console.log(resData)
const balance = resData.data.balance
const vip = resData.data.vip
// const message = resData.message || ''
// // 使用正则表达式解析余额和VIP等级
// const balanceMatch = message.match(/余额为:(\d+\.?\d*)元/)
// const vipMatch = message.match(/当前VIP等级为(\d+)/)
console.log("balance:"+balance+",vip:"+vip)
if (balance && vip) {
const message = resData.message || ''
// 使用正则表达式解析余额和VIP等级
const balanceMatch = message.match(/余额为:(\d+\.?\d*)元/)
const vipMatch = message.match(/当前VIP等级为(\d+)/)
if (balanceMatch && vipMatch) {
const balance = parseFloat(balanceMatch[1])
const vip = parseInt(vipMatch[1])
commit('setBalanceAndVip', { balance, vip })
} else {
console.warn('无法解析余额或VIP信息:', message)
@ -269,25 +260,24 @@ async returnBook({ dispatch }, { title }) {
}
const response = await service.get('/api/select', config)
const countResponse = await service.get('/api/countArticle')
// console.log('请求书籍:', params.title)
// console.log('API响应:', response)
console.log('请求书籍:', route.params.title)
console.log('API响应:', response)
// 处理不同响应格式
let list = []
let total = countResponse.data.data
let total = 0
if (Array.isArray(response)) {
list = response
// total = response.length
total = response.length
} else if (Array.isArray(response.data)) {
list = response.data
// total = response.data.length
total = response.data.length
} else if (response.data && Array.isArray(response.data.data)) {
list = response.data.data
// total = response.data.total || response.data.data.length
total = response.data.total || response.data.data.length
} else if (response.data && Array.isArray(response.data.list)) {
list = response.data.list
// total = response.data.total || response.data.list.length
total = response.data.total || response.data.list.length
}
return {
@ -318,23 +308,6 @@ async returnBook({ dispatch }, { title }) {
throw error
}
},
async fetchBookById(_, payload) {
const { id } = payload;
try {
const response = await service.get('/api/selectById/'+id)
// 根据接口文档处理响应
if (response.data && response.data.code === 200) {
return { data: response.data.data }
} else {
throw new Error(response.data?.message || '获取书籍信息失败')
}
} catch (error) {
console.error('API请求失败:', error)
throw error
}
},
// 新增书籍
async addBook(_, bookData) {

@ -17,7 +17,7 @@
<el-table :data="records" border style="width: 100%">
<el-table-column prop="borrower" label="用户名" width="150" />
<el-table-column prop="title" label="书名" width="200" />
<el-table-column prop="book_title" label="书名" width="200" />
<el-table-column prop="borrow_time" label="借阅时间" width="400">
<template #default="scope">
{{ formatDate(scope.row.borrow_time) }}
@ -76,14 +76,14 @@
{
id: 1,
borrower: 'zhangsan',
title: '三体',
book_title: '三体',
borrow_time: '2023-10-15 09:30:00',
return_time: null //
},
{
id: 2,
borrower: 'lisi',
title: '人类简史',
book_title: '人类简史',
borrow_time: '2023-10-10 14:20:00',
return_time: '2023-10-20 16:10:00' //
}

@ -76,7 +76,7 @@
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Search, Plus } from '@element-plus/icons-vue'
import service from '../../utils/request'
import axios from 'axios'
const router = useRouter()
const books = ref([])
@ -99,13 +99,10 @@
keyword: searchKeyword.value
}
const response = await service.get('/api/select', { params })
const countResponse = await service.get('/api/countArticle')
console.log("response")
console.log(response)
const response = await axios.get('/api/select', { params })
if (response.data.code === 200) {
books.value = response.data.data
total.value = countResponse.data.data
books.value = response.data.data.list
total.value = response.data.data.total
} else {
ElMessage.error('获取图书列表失败')
total.value = books.value.length

@ -69,20 +69,49 @@ const rules = ref({
const loginForm = ref(null)
const loading = ref(false)
// const login = async () => {
// try {
// await loginForm.value.validate()
// loading.value = true
// await store.dispatch('login', form.value)
// ElMessage.success('')
// //
// await store.dispatch('fetchUser')
// // localStorage
// const userInfo = store.state.user
// localStorage.setItem('userInfo', JSON.stringify(userInfo))
// //
// router.push('/')
// } catch (error) {
// console.error(':', error)
// ElMessage.error(error.message || '')
// } finally {
// loading.value = false
// }
// }
const login = async () => {
try {
//
await loginForm.value.validate()
loading.value = true
await store.dispatch('login', form.value)
ElMessage.success('登录成功')
// action
const response = await store.dispatch('login', form.value)
//
const userInfo = response.user
//
await store.dispatch('fetchUser')
// localStorage
const userInfo = store.state.user
localStorage.setItem('userInfo', JSON.stringify(userInfo))
//
// admin
store.commit('setUser', {
...userInfo,
admin: userInfo.admin === 1 // 1/0 true/false
})
ElMessage.success('登录成功')
router.push('/')
} catch (error) {
console.error('登录失败:', error)

@ -68,10 +68,10 @@ onMounted(async () => {
const fetchBook = async () => {
try {
loading.value = true
const id = route.params.id
console.log("id"+id)
const title = route.params.title
//
const response = await store.dispatch('fetchBookById',{id})
const response = await store.dispatch('fetchBookByTitle', { title })
// 2.3
if (response.data) {

@ -15,7 +15,7 @@
<el-button
type="primary"
@click="goToAddBook"
v-if="user && user.admin"
v-if="isAdmin"
class="add-button">
<el-icon><Plus /></el-icon>
添加书籍
@ -75,14 +75,15 @@ import { ElMessage } from 'element-plus'
const store = useStore()
const router = useRouter()
const user = computed(() => store.state.user)
const isAdmin = computed(() => user.value?.admin || false)
const books = ref([])
const searchKeyword = ref('')
const currentPage = ref(1)
const pageSize = ref(12)
const total = ref(0)
const isAdmin = computed(() => store.getters.isAdmin)
onMounted(() => {
fetchBooks()
})

@ -5,7 +5,7 @@
<div class="balance-display">
<el-text type="primary" size="large">
当前余额: <span class="balance-amount">{{ balance || 0 }}</span>
当前余额: <span class="balance-amount">{{ user.balance || 0 }}</span>
</el-text>
</div>
@ -43,19 +43,13 @@
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { ref, computed } from 'vue'
import { useStore } from 'vuex'
import { ElMessage } from 'element-plus'
import service from '../../utils/request'
const store = useStore()
const user = computed(() => store.state.user || {})
const balance = ref(0)
console.log(store.state.user)
onMounted(async ()=>{
const response = await service.post("/user/findmoney")
balance.value = response.data.data.balance
})
const form = ref({
money: 10
})

@ -1,68 +0,0 @@
package com.example.demo.controller;
import com.example.demo.mapper.BorrowMapper;
import com.example.demo.pojo.Article;
import com.example.demo.pojo.Borrow;
import com.example.demo.pojo.Result;
import com.example.demo.service.ArticleService;
import com.example.demo.service.BorrowService;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpSession;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
@RestController
@CrossOrigin
@RequestMapping("/borrow")
public class BorrowController {
@Autowired
private BorrowService borrowService;
@Autowired
private UserService userService;
@Autowired
private ArticleService articleService;
@Autowired
private BorrowMapper borrowMapper;
//租借书
@PostMapping("/borrowbook")
public Result borrowbook(String title, HttpSession session) {
Borrow borrow = new Borrow();
borrow.setTitle(title);
borrow.setBorrower((String) session.getAttribute("username"));
borrow.setBorrow_time(LocalDateTime.now());
Article article = articleService.selectonearticle(title);
float money = article.getMoney();
float balance = userService.findmoney(session.getAttribute("username"));
if (balance >= money) {
borrowService.borrow(borrow);
userService.deduct(money,session.getAttribute("username"));
return Result.success(borrow);
}
else{
return Result.error("余额不足!");
}
}
//还书
@PostMapping("/returnbook")
public Result returnbook(String title, HttpSession session){
Borrow borrow=new Borrow();
borrow.setTitle(title);
borrow.setBorrower((String) session.getAttribute("username"));
borrow.setReturn_time(LocalDateTime.now());
borrowService.returnbook(borrow);
borrowMapper.fine();
return Result.success(borrow);
}
}

@ -1,33 +0,0 @@
package com.example.demo.controller;
import com.example.demo.pojo.ArticleRentRankDTO;
import com.example.demo.service.BorrowRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/rank")
public class BorrowRankController {
@Autowired
private BorrowRankService borrowRankService;
/**
*
*/
@GetMapping("/weekly")
public List<ArticleRentRankDTO> weeklyRank() {
return borrowRankService.getWeeklyRank();
}
/**
*
*/
@GetMapping("/monthly")
public List<ArticleRentRankDTO> monthlyRank() {
return borrowRankService.getMonthlyRank();
}
}

@ -1,62 +0,0 @@
package com.example.demo.mapper;
import com.example.demo.pojo.Article;
import com.example.demo.pojo.Borrow;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface BorrowMapper {
//借书
@Insert("INSERT INTO borrow (title, borrower, borrow_time)\n" +
"VALUES \n" +
"(#{title}, #{borrower}, now())")
void borrowrecord(Borrow borrow);
// 更新对应物品的被租数量number+1
@Update("UPDATE article " +
"SET number = number + 1 " +
"WHERE title = #{title}")
void incrementArticleNumber(String title);
//还书
@Insert("INSERT INTO borrow (title, borrower, return_time)\n" +
"VALUES \n" +
"(#{title}, #{borrower}, now())")
void returnrecord(Borrow borrow);
//超过一个月罚金扣20元
@Update("UPDATE user\n" +
"SET balance = balance - 20\n" +
"WHERE username IN (\n" +
" SELECT username\n" +
" FROM borrow\n" +
" WHERE DATEDIFF(CURRENT_DATE(), borrow_time) > 30\n" +
");")
void fine();
//查询还借书记录(所有)
@Select("select * from borrow")
List<Borrow> findall();
//查询还书记录(个人)
@Select("select * from borrow where borrower=#{username}")
Borrow findone(String username);
//查询个人已经借的书的所有信息
@Select("SELECT a.* " +
"FROM article a " +
"INNER JOIN borrow b ON a.title = b.title " +
"INNER JOIN user u ON b.borrower = u.username " +
"WHERE u.username = #{username} " +
"AND b.borrow_time IS NOT NULL " +
"AND b.return_time IS NULL")
List<Article> findBorrowedBooksByUsername(String username);
}

@ -1,44 +0,0 @@
package com.example.demo.mapper;
import com.example.demo.pojo.ArticleRentRankDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface BorrowRankMapper {
/**
* Top10
*/
@Select("SELECT " +
"b.title, " +
"a.url, " +
"a.money, " +
"COUNT(b.title) AS number " +
"FROM borrow b " +
"LEFT JOIN article a ON b.title = a.title " +
"WHERE b.borrow_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY) " +
"AND b.borrow_time < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY) " +
"GROUP BY b.title, a.url, a.money " +
"ORDER BY number DESC " +
"LIMIT 10")
List<ArticleRentRankDTO> listWeeklyRank();
/**
* Top10
*/
@Select("SELECT " +
"b.title, " +
"a.url, " +
"a.money, " +
"COUNT(b.title) AS number " +
"FROM borrow b " +
"LEFT JOIN article a ON b.title = a.title " +
"WHERE b.borrow_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01') " +
"AND b.borrow_time < DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH) " +
"GROUP BY b.title, a.url, a.money " +
"ORDER BY number DESC " +
"LIMIT 10")
List<ArticleRentRankDTO> listMonthlyRank();
}

@ -1,63 +0,0 @@
package com.example.demo.mapper;
import com.example.demo.pojo.User;
import com.example.demo.pojo.info;
import org.apache.ibatis.annotations.*;
@Mapper
public interface UserMapper {
@Select("select * from user where username=#{username}")
User findByUserName(String username);
@Insert("insert into user(username,password,vip,create_time,update_time,admin,balance)" +
" values(#{username},#{password},#{vip},now(),now(),#{admin},#{balance})")
void add(String username,String password,int vip,int admin,float balance);
@Select("SELECT password FROM user WHERE username=#{username}")
String login(String username);
@Select("select username,pic from user where username=#{username}")
info getinfo( String username);
//充钱
@Update("UPDATE user\n" +
"SET balance=balance+#{money1}\n" +
"WHERE username=#{username};")
void recharge(float money1,String username);
//查询余额
@Select("select balance from user where username=#{username}")
float findbalance(Object username);
//更新VIP余额
@Update("UPDATE `user`\n" +
"SET `vip` = CASE\n" +
" WHEN `balance` >= 10 AND `balance` < 30 THEN '1'\n" +
" WHEN `balance` >= 30 AND `balance` < 100 THEN '2'\n" +
" WHEN `balance` >= 100 AND `balance` < 300 THEN '3'\n" +
" WHEN `balance` >= 300 AND `balance` < 500 THEN '4'\n" +
" WHEN `balance` >= 500 THEN '5'\n" +
" ELSE `vip` -- 不满足条件的记录保持原有vip值\n" +
"END\n" +
"WHERE `username` = #{username};")
void updateVIP( float balance,String username);
@Select("select vip from user where username=#{username}")
int findVIP(String username);
//扣钱
@Update("UPDATE user\n" +
"SET balance=balance-#{money1}\n" +
"WHERE username=#{username};")
void deduct(float money1,String username);
//管理员删除书
@Delete("DELETE FROM article WHERE title=#{title}")
void deletebook(String title);
}

@ -1,11 +0,0 @@
package com.example.demo.pojo;
import lombok.Data;
@Data
public class ArticleRentRankDTO {
private String title; // 物品名称
private String url; // 封面图片
private Float money; // 租借价格
private Integer number; // 租借次数
}

@ -1,28 +0,0 @@
package com.example.demo.service;
import com.example.demo.mapper.BorrowRankMapper;
import com.example.demo.pojo.ArticleRentRankDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BorrowRankService {
@Autowired // 改用Spring的@Autowired注解
private BorrowRankMapper borrowRankMapper;
/**
*
*/
public List<ArticleRentRankDTO> getWeeklyRank() {
return borrowRankMapper.listWeeklyRank();
}
/**
*
*/
public List<ArticleRentRankDTO> getMonthlyRank() {
return borrowRankMapper.listMonthlyRank();
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save