Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
|
bbb8eba5d1 | 4 weeks ago |
|
7533450cc6 | 4 weeks ago |
|
d4b3ce78ae | 4 weeks ago |
|
6afa988017 | 4 weeks ago |
|
19862dc69d | 4 weeks ago |
|
9e8ce09450 | 4 weeks ago |
|
b5bf87ce53 | 4 weeks ago |
|
b2e3d51c0e | 4 weeks ago |
|
44c71c9562 | 1 month ago |
|
ddc810f5ed | 1 month ago |
|
466d816aa2 | 1 month ago |
|
4730b9962b | 1 month ago |
Binary file not shown.
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
@ -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,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();
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue