网上出版的电子书只有购买服务,如果也有租赁服务就好了。例如,读者可以租个1个小时,1个小时到期,读者就不能阅读该书。
图中借阅结束时间是2024-04-23 13:36:29,到期后该书就会从列表中消失。
BookOrderMapper.xml
<?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.ruoyi.system.mapper.BookOrderMapper"><resultMap type="BookOrder" id="BookOrderResult"><result property="orderId" column="order_id" /><result property="userId" column="user_id" /><result property="bookId" column="book_id" /><result property="startTime" column="start_time" /><result property="endTime" column="end_time" /></resultMap><sql id="selectBookOrderVo">select order_id, user_id, book_id, start_time, end_time from book_order</sql><select id="selectBookOrderList" parameterType="BookOrder" resultMap="BookOrderResult"><include refid="selectBookOrderVo"/><where> <if test="userId != null "> and user_id = #{userId}</if><if test="bookId != null "> and book_id = #{bookId}</if><if test="startTime != null "> and start_time = #{startTime}</if><if test="endTime != null "> and end_time = #{endTime}</if>and end_time >= now()</where></select><select id="selectBookOrderByOrderId" parameterType="Long" resultMap="BookOrderResult"><include refid="selectBookOrderVo"/>where order_id = #{orderId}</select><insert id="insertBookOrder" parameterType="BookOrder" useGeneratedKeys="true" keyProperty="orderId">insert into book_order<trim prefix="(" suffix=")" suffixOverrides=","><if test="userId != null">user_id,</if><if test="bookId != null">book_id,</if><if test="startTime != null">start_time,</if><if test="endTime != null">end_time,</if></trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="userId != null">#{userId},</if><if test="bookId != null">#{bookId},</if><if test="startTime != null">#{startTime},</if><if test="endTime != null">#{endTime},</if></trim></insert><update id="updateBookOrder" parameterType="BookOrder">update book_order<trim prefix="SET" suffixOverrides=","><if test="userId != null">user_id = #{userId},</if><if test="bookId != null">book_id = #{bookId},</if><if test="startTime != null">start_time = #{startTime},</if><if test="endTime != null">end_time = #{endTime},</if></trim>where order_id = #{orderId}</update><delete id="deleteBookOrderByOrderId" parameterType="Long">delete from book_order where order_id = #{orderId}</delete><delete id="deleteBookOrderByOrderIds" parameterType="String">delete from book_order where order_id in <foreach item="orderId" collection="array" open="(" separator="," close=")">#{orderId}</foreach></delete></mapper>
BookOrderController.java
package com.ruoyi.web.controller.system;import java.util.List;import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BookOrder;
import com.ruoyi.system.service.IBookOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;import javax.security.auth.login.LoginContext;/*** bookorderController* * @author ruoyi* @date 2024-04-23*/
@Controller
@RequestMapping("/system/order")
public class BookOrderController extends BaseController
{private String prefix = "system/order";@Autowiredprivate IBookOrderService bookOrderService;@RequiresPermissions("system:order:view")@GetMapping()public String order(){return prefix + "/order";}/*** 查询bookorder列表*/@RequiresPermissions("system:order:list")@PostMapping("/list")@ResponseBodypublic TableDataInfo list(BookOrder bookOrder){bookOrder.setUserId(ShiroUtils.getUserId());startPage();List<BookOrder> list = bookOrderService.selectBookOrderList(bookOrder);return getDataTable(list);}/*** 导出bookorder列表*/@RequiresPermissions("system:order:export")@Log(title = "bookorder", businessType = BusinessType.EXPORT)@PostMapping("/export")@ResponseBodypublic AjaxResult export(BookOrder bookOrder){List<BookOrder> list = bookOrderService.selectBookOrderList(bookOrder);ExcelUtil<BookOrder> util = new ExcelUtil<BookOrder>(BookOrder.class);return util.exportExcel(list, "bookorder数据");}/*** 新增bookorder*/@GetMapping("/add")public String add(){return prefix + "/add";}/*** 新增保存bookorder*/@RequiresPermissions("system:order:add")@Log(title = "bookorder", businessType = BusinessType.INSERT)@PostMapping("/add")@ResponseBodypublic AjaxResult addSave(BookOrder bookOrder){return toAjax(bookOrderService.insertBookOrder(bookOrder));}/*** 修改bookorder*/@RequiresPermissions("system:order:edit")@GetMapping("/edit/{orderId}")public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap){BookOrder bookOrder = bookOrderService.selectBookOrderByOrderId(orderId);mmap.put("bookOrder", bookOrder);return prefix + "/edit";}/*** 修改保存bookorder*/@RequiresPermissions("system:order:edit")@Log(title = "bookorder", businessType = BusinessType.UPDATE)@PostMapping("/edit")@ResponseBodypublic AjaxResult editSave(BookOrder bookOrder){return toAjax(bookOrderService.updateBookOrder(bookOrder));}/*** 删除bookorder*/@RequiresPermissions("system:order:remove")@Log(title = "bookorder", businessType = BusinessType.DELETE)@PostMapping( "/remove")@ResponseBodypublic AjaxResult remove(String ids){return toAjax(bookOrderService.deleteBookOrderByOrderIds(ids));}
}
ShiroUtils.getUserId()可以获取当前登录用户的user_id。
BookOrder.java
package com.ruoyi.system.domain;import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;/*** bookorder对象 book_order* * @author ruoyi* @date 2024-04-23*/
public class BookOrder extends BaseEntity
{private static final long serialVersionUID = 1L;/** */private Long orderId;/** */@Excel(name = "")private Long userId;/** */@Excel(name = "")private Long bookId;/** */@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")@Excel(name = "", width = 30, dateFormat = "yyyy-MM-dd")private Date startTime;/** */@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")@Excel(name = "", width = 30, dateFormat = "yyyy-MM-dd")private Date endTime;public void setOrderId(Long orderId) {this.orderId = orderId;}public Long getOrderId() {return orderId;}public void setUserId(Long userId) {this.userId = userId;}public Long getUserId() {return userId;}public void setBookId(Long bookId) {this.bookId = bookId;}public Long getBookId() {return bookId;}public void setStartTime(Date startTime) {this.startTime = startTime;}public Date getStartTime() {return startTime;}public void setEndTime(Date endTime) {this.endTime = endTime;}public Date getEndTime() {return endTime;}@Overridepublic String toString() {return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE).append("orderId", getOrderId()).append("userId", getUserId()).append("bookId", getBookId()).append("startTime", getStartTime()).append("endTime", getEndTime()).toString();}
}