• 基于javaweb+mysql的电影票售票管理系统


    基于javaweb+mysql的电影票售票管理系统

    运行环境

    Java≥8、MySQL≥5.7、Tomcat≥8

    开发工具

    eclipse/idea/myeclipse/sts等均可配置运行

    适用

    课程设计,大作业,毕业设计,项目练习,学习演示等

    功能说明

    后台:管理用户、影片、排片、影厅、订单、影评等

    前台:注册登录、查看排片、详情,选座、购票等

    后台

    前台

    技术框架

    JSP Servlet MySQL C3P0 DBUtil Tomcat JavaScript CSS


    适用

    课程设计,大作业,毕业设计,项目练习,学习演示等

                }
            }
        }
    
        private void doDel(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            String movieName = req.getParameter("movie");
            if (movieName != null) {
                Movie movie = service.deleteByName(movieName);
                //删除成功的话,把原图片一起删除
                if (movie != null) {
                    new File(getServletContext().getRealPath(GetImageServlet.IMG_SERVLET_DIR), movie.pic_name).delete();
                }
            }
            forwardToMoviesJsp(service.queryAll(), req, resp);
        }
    
        private void doUpdateMovie(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {        
            String movieName = req.getParameter("movie");
            if (movieName != null) {
                //查询到则返回,没有则返回影片管理
                Movie movie = service.queryByName(movieName);
                if (movie == null) {
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
            if (Utils.isEmpty(plan.movie_name)) {
                throw new MyException("片名不能为空");
            } else if (Utils.isEmpty(plan.hall_name)) {
                throw new MyException("请选择影厅");
            } else if (plan.price == 0) {
                throw new MyException("价格必须是大于0的数字");
            } else if (plan.play_time == 0) {
                throw new MyException("放映时间格式不正确");
            } else if (plan.play_time < System.currentTimeMillis() + 3600000) {
                throw new MyException("放映时间必须比当前时间晚1小时");
            } else {
                //遍历所有排片,看是否有冲突
                List<Plan> list = planDao.queryAll();
                if (list == null) {
                    planDao.add(plan);
                } else {
                    //获取当前影片片长
                    Movie movie = movieDao.query(new String[]{MovieDao.COLUME_NAME}, plan.movie_name);
                    long endTime = plan.play_time + movie.duration * 60000;//片长是以分钟单位保存的,转成毫秒
                    for (Plan p : list) {
                        //如果使用的是同一个影厅,开始判断时间是否有交叉
                        //同影厅放映电影时间间隔为半小时
                        if (p.hall_name.equals(plan.hall_name)) {
                            //获取此排片的电影
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
                if ((beginIndex=fileName.lastIndexOf("\\")) != -1) {
                    fileName = fileName.substring(beginIndex+1);
                }
                if ((beginIndex=fileName.lastIndexOf("/")) != -1) {
                    fileName = fileName.substring(beginIndex+1);
                }
                return deleteSuffix(fileName);
            }
            return deleteSuffix(path);
        }
    
        /**
         * 获取扩展名
         * @param s 路径或后缀
         * @return 不存在后缀时返回null
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/table.css"/>
        <script src="${pageContext.request.contextPath}/js/my.js">script>
        <script src="${pageContext.request.contextPath}/js/echarts.common.min.js">script>
        <style>
            .content {
                width: 1000px;
                margin: 20px auto;
                background: white;
            }
            .nav_bar {
                margin: 0;
                border-bottom: 1px solid #65B336;
            }
            .space {
                width: 100%;
                height: 10px;
                background: #E9E9E9;
            }
            table {
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
            FileInputStream inStream = null;
            FileOutputStream outStream = null;
            try {
                inStream = new FileInputStream(source);
                outStream = new FileOutputStream(target);
                in = inStream.getChannel();
                out = outStream.getChannel();
                in.transferTo(0, in.size(), out);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    IOUtils.close(in, out, inStream, outStream);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
                        if (file.isDirectory()) {
                            size += getDirSize(file);
                        } else {
                            size += file.length();
                        }
                    }
                    return size;
                }
                return 0;
            }
            return -1;
        }
    
        /**
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
                    <a class="buy" href="${pageContext.request.contextPath}/login?from=/movie/detail">购票a>
                c:if>
                <c:if test="${!empty sessionScope.user}">
                    <a class="buy" href="${pageContext.request.contextPath}/sessions?movie=${movie.name}">购票a>
                c:if>            
            div>
        div>
        <div class="synopsis">
            <p class="title">剧情简介:p>
            <p>      ${movie.synopsis}p>
        div>
    div>
    <div class="evaluate">
        <div class="title_bar">
            <span class="title">影评span>
            <c:if test="${empty sessionScope.user}">
                <a class="write" href="${pageContext.request.contextPath}/login?from=/movie/detail">写影评a>
            c:if>
            <c:if test="${!empty sessionScope.user}">
                <a class="write" onclick="document.getElementById('write_eva').scrollIntoView()">写影评a>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
                        var inputNode = document.getElementsByName(node.className);
                        if (node.alt === "available") {
                            node.src = "images/selected.png";
                            node.alt = "selected";
                            inputNode[0].value = 1;
                            selectNum++;
                        } else {
                            node.src = "images/available.png";
                            node.alt = "available";
                            inputNode[0].value = 0;
                            selectNum--;
                        }
                        var amount = Math.floor(price * selectNum * 100) / 100;
                        var num = amount.toString();
                        var index = num.indexOf(".");
                        if (index < 0) {
                            index = num.length;
                            num += ".";
                        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
            return (int) ((dateB - dateA) / (24 * 3600000L));
        }
    
        /**
         * 将此日期时间设置成0点整
         */
        public static Calendar getStartOfDay(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
    
        /**
         * 将此日期时间设置成0点整
         */
        public static long getStartOfDay(long date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date(date));
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
                    <img class="pic" src="${pageContext.request.contextPath}/img?file=${movie.pic_name}" title="${movie.name}">
                    <div class="txt">
                        <p class="movie_name">${movie.name}p>
                        <p class="info">导演: ${movie.director}p>
                        <p class="info">主演: ${movie.protagonist}p>
                        <p class="info">类型: ${movie.type}p>
                        <p class="info">国家 / 地区: ${movie.region}p>
                        <p class="info">语言: ${movie.language}p>
                        <p class="info">片长: ${movie.duration}分钟p>
                        <p class="synopsis">剧情简介: ${movie.synopsis}p>
                    div>
                    <div class="action_block">
                        <c:if test="${empty sessionScope}">
                            <a class="blue_a" href="${pageContext.request.contextPath}/login">购票a>
                        c:if>
                        <c:if test="${!empty sessionScope}">
                            <a class="blue_a" href="${pageContext.request.contextPath}/sessions?movie=${movie.name}">购票a>                        
                        c:if>
                        <a class="blue_a" href="${pageContext.request.contextPath}/movie/detail?movie=${movie.name}">详情a>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
                orderDao.delete(new String[]{OrderDao.COLUME_USER_ID}, id);
            }
            return result;
        }
    
        @Override
        public User valicateUser(String username, String password) throws MyException {
            if (Utils.isEmpty(username)) {
                throw new MyException("用户名不能为空");
            } else if (Utils.isEmpty(password)) {
                throw new MyException("密码不能为空");
            } else if (userDao.query(new String[]{UserDao.COLUME_USERNAME}, username) == null) {
                throw new MyException("用户不存在");
            } else {
                User user = userDao.valicateUser(username, password);
                if (user == null) {
                    throw new MyException("用户名或密码不正确");
                }
                return user;
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
            if (plan != null) {
                MoviceService moviceService = BaseFactory.getService(MoviceService.class);
                Movie movie = moviceService.queryByName(plan.movie_name);
                HallService hallService = BaseFactory.getService(HallService.class);
                Hall hall = hallService.queryByName(plan.hall_name);
                if (movie != null && hall != null) {
                    Ticket ticket = new Ticket();
                    ticket.orderId = order.id;
                    ticket.buyTime = DateUtils.formatDate(order.create_time, "yyyy-MM-dd HH:mm");
                    ticket.movieName = plan.movie_name;
                    ticket.picName = movie.pic_name;
                    ticket.hallName = plan.hall_name;
                    ticket.playTime = DateUtils.formatDate(plan.play_time, "yyyy-MM-dd HH:mm");
                    ticket.endTime = DateUtils.formatDate(plan.play_time + movie.duration * 60000, "HH:mm");
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
        public static boolean isSame(int field, Calendar date1, Calendar date2) {
            if (date1 == null || date2 == null) {
                return false;
            }
            switch(field) {
                case Calendar.DATE:
                    return date1.get(Calendar.ERA) == date2.get(Calendar.ERA) &&
                            date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR) &&
                            date1.get(Calendar.DAY_OF_YEAR) == date2.get(Calendar.DAY_OF_YEAR);
                case Calendar.MONTH:
                    return date1.get(Calendar.ERA) == date2.get(Calendar.ERA) &&
                            date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR) &&
                            date1.get(Calendar.MONTH) == date2.get(Calendar.MONTH);
                case Calendar.YEAR:
                    return date1.get(Calendar.ERA) == date2.get(Calendar.ERA) &&
                            date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR);
                default:		
            		return false;
            }
        }
        
        /**
         * 获取基于当前日期偏移后的日期
         *
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
        }
    }
    <%@ page import="com.demo.entity.Sale" %>
    <%@ page import="java.util.List" %>
    <%@ page import="java.util.Collections" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>票房统计title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mgr_head.css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/table.css"/>
        <script src="${pageContext.request.contextPath}/js/my.js">script>
        <script src="${pageContext.request.contextPath}/js/echarts.common.min.js">script>
        <style>
            .content {
                width: 1000px;
                margin: 20px auto;
                background: white;
            }
            .nav_bar {
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
                //校验参数有效性
                service.valicateMovie(movie);
                movie.pic_name = fileName;
                if (add) {
                    service.addMovie(movie);                
                } else {
                    //如果修改了图片,把原来的图片删除
                    Movie m = service.updateMovie(movie);
                    //修改失败删除图片
                    if (m == null) {
                        if (fileName != null) {
                            new File(uploadPath, fileName).delete();
                        }
                    } else if (fileName != null && !fileName.equals(m.pic_name)) {
                        new File(uploadPath, m.pic_name).delete();    
                    }
                }
                resp.sendRedirect(req.getContextPath() + "/admin/movies");
            } catch (MyException e) {
                req.setAttribute("msg", e.getMessage());
                //将原来填写的返回
                Utils.fillAttr(req, map, "name");
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    head>
    <body>
        <div class="content">
            <%@include file="head.jsp"%>
            <div class="desc">
                <img class="desc_img" src="images/available.png"><span>可选span>
                <img class="desc_img" src="images/sold.png"><span>已售span>
                <img class="desc_img" src="images/selected.png"><span>已选span>
                <p class="amount">合计: p>
                <p id="total">¥0p>
            div>
            <p class="screen">银幕p>
            <div class="seat_area">
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13


    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述
    请添加图片描述

  • 相关阅读:
    使用 Web HID API 在浏览器中进行HID设备交互(纯前端)
    使用 Flet Python 框架构建 Markdown 编辑器 Flutter 应用程序
    Red Hat 8 安装Docker返回找不到镜像的问题(Status code: 404)
    1072 Gas Station
    【Unity入门计划】基本概念(6)-精灵渲染器 Sprite Renderer
    自然语言处理学习笔记(十一)————简繁转换与拼音转换
    EasyRecovery15最新版功能强大的电脑数据恢复
    笔记本电脑使用时需要一直插电吗?笔记本正确的充电方式
    秋招面试题系列- - -Java 工程师(一)
    WorkPlus Meet私有化部署视频会议,打造更安全的沟通体验
  • 原文地址:https://blog.csdn.net/m0_68109957/article/details/127741415