文章目录
- 电影院购票管理系统
- 一、项目演示
- 二、项目介绍
- 三、部分功能截图
- 四、部分代码展示
- 五、底部获取项目源码(9.9¥带走)
电影院购票管理系统
一、项目演示
电影院售票管理系统
二、项目介绍
基于springboot+vue的前后端分离电影院购票管理系统
(1)用户功能
登录、退出、注册、修改个人信息、上映|即将上映|热播影片浏览、搜索、上映|即将上映|热播榜单浏览、选座购票、订单查看
(2)管理员功能
影院信息管理、影片管理:电影信息、电影类型、影厅管理:影厅信息、场次信息管理、订单管理、用户管理
2、项目技术
语言:java
前端技术:Vue、Element-Plus
后端技术:SpringBoot、Mybatis-Plus
数据库:MySQL
三、部分功能截图
四、部分代码展示
package com.movie.web.controller.system;import com.movie.common.exception.DataNotFoundException;
import com.movie.common.response.ResponseResult;
import com.movie.common.utils.ApplicationContextUtils;
import com.movie.system.domin.SysBill;
import com.movie.system.domin.SysMovie;
import com.movie.system.domin.SysSession;
import com.movie.system.domin.vo.SysBillVo;
import com.movie.system.service.impl.SysBillServiceImpl;
import com.movie.system.service.impl.SysMovieServiceImpl;
import com.movie.system.service.impl.SysSessionServiceImpl;
import com.movie.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;import java.util.List;
import java.util.Random;@RestController
public class SysBillController extends BaseController {@Autowiredprivate SysBillServiceImpl sysBillService;@Autowiredprivate SysSessionServiceImpl sysSessionService;@Autowiredprivate SysMovieServiceImpl sysMovieService;@GetMapping("/sysBill")public ResponseResult findAllBills(SysBill sysBill) {startPage();// 取消所有超时订单并释放占座资源ApplicationContextUtils.getBean("cancelTimeoutBill");List<SysBill> data = sysBillService.findAllBills(sysBill);return getResult(data);}@GetMapping("/sysBill/{id}")public ResponseResult findBillById(@PathVariable Long id) {return getResult(sysBillService.findBillById(id));}@PostMapping("/sysBill")public ResponseResult addBill(@Validated @RequestBody SysBillVo sysBillVo) {// 获取当前场次信息SysSession curSession = sysSessionService.findOneSession(sysBillVo.getSysBill().getSessionId());if (curSession == null) {throw new DataNotFoundException("添加订单的场次没找到");}System.out.println(curSession.getSessionSeats());curSession.setSessionSeats(sysBillVo.getSessionSeats());int addSallNums = sysBillVo.getSysBill().getSeats().split(",").length;curSession.setSallNums(curSession.getSallNums() + addSallNums);// 更新场次座位信息sysSessionService.updateSession(curSession);Random random = new Random();int temp = random.nextInt(6);Object obj = sysBillService.addBill(sysBillVo.getSysBill());if (obj instanceof Integer) {return getResult((Integer) obj);}return getResult(obj);}@PutMapping("/sysBill")public ResponseResult pay(@RequestBody SysBill sysBill) {int rows = sysBillService.updateBill(sysBill);if (rows > 0 && sysBill.getPayState()) {//更新场次的座位状态SysSession curSession = sysSessionService.findOneSession(sysBill.getSessionId());if (curSession == null) {throw new DataNotFoundException("支付订单的场次没找到");}//更新电影票房SysMovie curMovie = sysMovieService.findOneMovie(curSession.getMovieId());if (curMovie == null) {throw new DataNotFoundException("支付订单的电影没找到");}//订单的座位数int seatNum = sysBill.getSeats().split(",").length;double price = curSession.getSessionPrice();curMovie.setMovieBoxOffice(curMovie.getMovieBoxOffice() + seatNum * price);sysMovieService.updateMovie(curMovie);}return getResult(rows);}@PutMapping("/sysBill/cancel")public ResponseResult cancel(@RequestBody SysBillVo sysBillVo) {// 订单取消,更新订单状态int rows = sysBillService.updateBill(sysBillVo.getSysBill());if (rows > 0 && sysBillVo.getSysBill().getCancelState()) {// 订单取消座位不再占用,更新场次的座位状态SysSession curSession = sysSessionService.findOneSession(sysBillVo.getSysBill().getSessionId());// 取消的订单座位数int cancelSallNums = sysBillVo.getSysBill().getSeats().split(",").length;curSession.setSallNums(curSession.getSallNums() - cancelSallNums);if (curSession == null) {throw new DataNotFoundException("添加订单的场次没找到");}curSession.setSessionSeats(sysBillVo.getSessionSeats());sysSessionService.updateSession(curSession);}return getResult(rows);}@DeleteMapping("/sysBill/{ids}")public ResponseResult deleteBill(@PathVariable Long[] ids) {return getResult(sysBillService.deleteBill(ids));}}
package com.movie.web.controller.system;import com.movie.common.response.ResponseResult;
import com.movie.system.domin.SysCinema;
import com.movie.system.domin.SysSession;
import com.movie.system.service.impl.SysCinemaServiceImpl;
import com.movie.system.service.impl.SysSessionServiceImpl;
import com.movie.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;import java.util.HashMap;
import java.util.List;@RestController
public class SysCinemaController extends BaseController {@Autowiredprivate SysCinemaServiceImpl sysCinemaService;@Autowiredprivate SysSessionServiceImpl sysSessionService;@GetMapping("/sysCinema")public ResponseResult findCinema() {return getResult(sysCinemaService.findCinema());}@PutMapping("/sysCinema/update")public ResponseResult updateCinema(@Validated @RequestBody SysCinema sysCinema) {return getResult(sysCinemaService.updateCinema(sysCinema));}@GetMapping(value = {"/sysCinema/find/{cinemaId}/{movieId}", "/sysCinema/find/{cinemaId}"})public ResponseResult findCinemaById(@PathVariable Long cinemaId, @PathVariable(required = false) Long movieId) {SysCinema cinema = sysCinemaService.findCinemaById(cinemaId);if (movieId == null || movieId == 0) {movieId = cinema.getSysMovieList().size() > 0 ? cinema.getSysMovieList().get(0).getMovieId() : 0;}List<SysSession> sessions = null;if (movieId != null && movieId != 0) {sessions = sysSessionService.findSessionByMovieId(movieId);}HashMap<String, Object> response = new HashMap<>();response.put("cinema", cinema);response.put("sessions", sessions);return getResult(response);}}
package com.movie.common.controller;import com.movie.common.file.FileUploadUtils;
import com.movie.common.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;import java.io.FileNotFoundException;
import java.io.IOException;/*** 封装图片上传请求*/
@Slf4j
@RestController
@RequestMapping("/upload")
public class FileUploadController {@PostMapping("/user")public ResponseResult uploadUser(@RequestParam("file") MultipartFile file) throws IOException {FileUploadUtils.setDefaultBaseDir(FileUploadUtils.userPath);String filename = FileUploadUtils.upload(file);log.debug("上传文件名 : " + filename);return ResponseResult.success((Object) filename);}@PostMapping("/movie")public ResponseResult uploadMovie(@RequestParam("file") MultipartFile file) throws IOException {FileUploadUtils.setDefaultBaseDir(FileUploadUtils.moviePath);String filename = FileUploadUtils.upload(file);log.debug("上传文件名 : " + filename);return ResponseResult.success((Object) filename);}@PostMapping("/cinema")public ResponseResult uploadCinema(@RequestParam("file") MultipartFile file) throws IOException {FileUploadUtils.setDefaultBaseDir(FileUploadUtils.cinemaPath);String filename = FileUploadUtils.upload(file);log.debug("上传文件名 : " + filename);return ResponseResult.success((Object) filename);}@PostMapping("/actor")public ResponseResult uploadActor(@RequestParam("file") MultipartFile file) throws IOException {FileUploadUtils.setDefaultBaseDir(FileUploadUtils.actorPath);String filename = FileUploadUtils.upload(file);log.debug("上传文件名 : " + filename);return ResponseResult.success((Object) filename);}@RequestMapping("/delete")public ResponseResult deletePicture(String filePath) {try {String path = ResourceUtils.getURL("classpath:").getPath().substring(1) + "static" + filePath;log.debug("删除文件路径为:" + path);boolean flag = FileUploadUtils.deleteFile(path);log.debug(flag ? "删除成功" : "删除失败");} catch (FileNotFoundException e) {System.out.println("删除文件不存在");} finally {return ResponseResult.success();}}}
package com.movie.common.file;import com.movie.common.exception.FileNameLengthLimitExceededException;
import com.movie.common.exception.FileSizeLimitExceededException;
import com.movie.common.exception.InvalidExtensionException;
import com.movie.common.utils.StringUtil;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.util.ClassUtils;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;/*** 文件上传工具类*/
public class FileUploadUtils {/*** 默认大小 50M*/public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;/*** 默认的文件名最大长度 100*/public static final int DEFAULT_FILE_NAME_LENGTH = 100;/*** 默认存储图片目录*/private static final String parentPath = ClassUtils.getDefaultClassLoader().getResource("static/images").getPath();public static final String actorPath = "/actor";public static final String cinemaPath = "/cinema";public static final String moviePath = "/movie";public static final String userPath = "/user";/*** 默认上传的地址*/private static String defaultBaseDir = userPath;public static void setDefaultBaseDir(String defaultBaseDir) {FileUploadUtils.defaultBaseDir = defaultBaseDir;}public static String getDefaultBaseDir() {return defaultBaseDir;}public static String getParentPath() {return parentPath;}/*** 以默认配置进行文件上传** @param file 上传的文件* @return 文件名称* @throws Exception*/public static final String upload(MultipartFile file) throws IOException {try {return upload(getParentPath() + getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);} catch (Exception e) {throw new IOException(e.getMessage(), e);}}/*** 文件上传** @param baseDir 相对应用的基目录* @param file 上传的文件* @param allowedExtension 上传文件类型* @return 返回上传成功的文件名* @throws FileSizeLimitExceededException 如果超出最大大小* @throws FileNameLengthLimitExceededException 文件名太长* @throws IOException 比如读写文件出错时* @throws InvalidExtensionException 文件校验异常*/public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,InvalidExtensionException {int fileNamelength = file.getOriginalFilename().length();if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {throw new FileNameLengthLimitExceededException("文件名称长度不能超过" + FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);}assertAllowed(file, allowedExtension);String fileName = extractFilename(file);File desc = getAbsoluteFile(baseDir, fileName);System.err.println("baseDir"+": "+baseDir);file.transferTo(desc);String pathFileName = getPathFileName(baseDir, fileName);System.err.println("pathFileName"+": "+baseDir);return pathFileName;}/*** 编码文件名 如 : images/user/2021/3/4/***.png*/public static final String extractFilename(MultipartFile file) {String fileName = file.getOriginalFilename();String extension = getExtension(file);fileName = DateFormatUtils.format(new Date(), "yyyy/MM/dd") + "/" + UUID.randomUUID().toString().replaceAll("-", "") + "." + extension;System.err.println("fileName"+": "+fileName);return fileName;}/*** 判断文件名是否存在 不存在创建一个* @param uploadDir* @param fileName* @return* @throws IOException*/private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {File desc = new File(uploadDir + File.separator + fileName);if (!desc.getParentFile().exists()) {desc.getParentFile().mkdirs();}if (!desc.exists()) {desc.createNewFile();}return desc;}private static final String getPathFileName(String uploadDir, String fileName) throws IOException {int dirLastIndex = parentPath.length() + 1;String currentDir = StringUtils.substring(uploadDir, dirLastIndex);String pathFileName = "/images/" + currentDir + "/" + fileName;return pathFileName;}/*** 文件大小校验** @param file 上传的文件* @return* @throws FileSizeLimitExceededException 如果超出最大大小* @throws InvalidExtensionException*/public static final void assertAllowed(MultipartFile file, String[] allowedExtension)throws FileSizeLimitExceededException, InvalidExtensionException {long size = file.getSize();if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) {throw new FileSizeLimitExceededException("文件大小不能超过" + DEFAULT_MAX_SIZE / 1024 / 1024 + "MB");}String fileName = file.getOriginalFilename();String extension = getExtension(file);if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) {throw new InvalidExtensionException("图片格式不支持" + extension + "格式");}}}/*** 判断MIME类型是否是允许的MIME类型** @param extension* @param allowedExtension* @return*/public static final boolean isAllowedExtension(String extension, String[] allowedExtension) {for (String str : allowedExtension) {if (str.equalsIgnoreCase(extension)) {return true;}}return false;}/*** 获取文件名的后缀** @param file 表单文件* @return 后缀名*/public static final String getExtension(MultipartFile file) {String extension = FilenameUtils.getExtension(file.getOriginalFilename());if (!StringUtil.isNotEmpty(extension)) {extension = MimeTypeUtils.getExtension(file.getContentType());}return extension;}/*** 删除文件** @param filePath 文件* @return*/public static boolean deleteFile(String filePath) {boolean flag = false;File file = new File(filePath);// 路径为文件且不为空则进行删除if (file.isFile() && file.exists()) {file.delete();flag = true;}return flag;}}
五、底部获取项目源码(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以