基于javaweb+mysql的springboot电影购票管理系统(java+springboot+vue+maven+mysql)

基于javaweb+mysql的springboot电影购票管理系统(java+springboot+vue+maven+mysql)

运行环境

Java≥8、MySQL≥5.7、Node.js≥10

开发工具

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

前端:WebStorm/VSCode/HBuilderX等均可

适用

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

功能说明

基于javaweb+mysql的SpringBoot电影购票管理系统(java+springboot+vue+maven+mysql)

一、项目运行 环境配置:

Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。

项目技术:

Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。


/**
 * Authorization 授权 发放token
 */
public class AuthorizationFilter extends BasicAuthenticationFilter {

    public AuthorizationFilter(AuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        //从Request Header 取出Token
        String token = request.getHeader(JwtTokenUtil.TOKEN_HEADER);

        //Token为空放行
        //如果接下来进入的URL不是公共的地址SpringSecurity会返回403的错误
        if (token == null || "null".equals(token)) {
            chain.doFilter(request, response);
            return;
        }

        //判断JWT Token是否过期
        if (JwtTokenUtil.isExpiration(token)) {
            ResponseUtil.writeJson(response, new ResponseResult<>(403, "令牌已过期, 请重新登录"));
            return;
        }

        //解析JWT获取用户信息
        String username = JwtTokenUtil.getUsername(token);
        ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<>();
        for (String role : JwtTokenUtil.getTokenRoles(token)) {
            authorities.add(new SimpleGrantedAuthority(role));
        }

        //向SpringSecurity的Context中加入认证信息
        SecurityContextHolder.getContext().setAuthentication(
                new UsernamePasswordAuthenticationToken(username, null, authorities));
        super.doFilterInternal(request, response, chain);
    }

/**
 * Authorization 授权 发放token
 */
public class AuthorizationFilter extends BasicAuthenticationFilter {

    public AuthorizationFilter(AuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        //从Request Header 取出Token
        String token = request.getHeader(JwtTokenUtil.TOKEN_HEADER);

        //Token为空放行
        //如果接下来进入的URL不是公共的地址SpringSecurity会返回403的错误
        if (token == null || "null".equals(token)) {
            chain.doFilter(request, response);
            return;
        }

        //判断JWT Token是否过期
        if (JwtTokenUtil.isExpiration(token)) {
            ResponseUtil.writeJson(response, new ResponseResult<>(403, "令牌已过期, 请重新登录"));
            return;
        }

        //解析JWT获取用户信息
        String username = JwtTokenUtil.getUsername(token);
        ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<>();
        for (String role : JwtTokenUtil.getTokenRoles(token)) {
            authorities.add(new SimpleGrantedAuthority(role));
        }

        //向SpringSecurity的Context中加入认证信息
        SecurityContextHolder.getContext().setAuthentication(
                new UsernamePasswordAuthenticationToken(username, null, authorities));
        super.doFilterInternal(request, response, chain);
    }
    public void reply(@RequestBody LeavingMessage leavingMessage) {
        leavingMessageService.reply(leavingMessage);
    }

    @GetMapping("")
    @ApiOperation("获取所有影院留言")
    public List<LeavingMessageVO> list() {
        return leavingMessageService.findAll();
    }

    @GetMapping("/active")
    @ApiOperation("获取活跃留言的用户")
    public List<ActiveUserVO> findActiveUsers() {
        return leavingMessageService.findActiveUsers();
    }

}

@RestController
@Api(tags = "活动接口")
@RequestMapping("/api/activity")
public class ActivityController {

    @Resource
    private ActivityService activityService;

    @PostMapping("")
    @ApiOperation("新增活动")
    public void create(@RequestBody Activity activity) {
        activityService.create(activity);
    }

@RequestMapping("/api/film")
public class FilmController {

    @Resource
    private FilmService filmService;

    @PostMapping("")
    @ApiOperation(value = "保存电影")
    public void save(@RequestBody Film film) {
        filmService.save(film);
    }

    @GetMapping("")
    @ApiOperation("列出所有电影")
    public List<Film> list(String region, String type) {
        if (region != null && type != null) {
            return filmService.findByRegionAndType(region, type);
        }
        return filmService.findAll();
    }

    @GetMapping("/hot/{limit}")
    @ApiOperation("获取热榜电影")
    public List<Film> listHots(@PathVariable Integer limit) {
        return filmService.findHots(limit);
    }

    @GetMapping("/name/{name}")
    @ApiOperation("搜索电影")
    public List<Film> search(@PathVariable String name) {
        return filmService.findLikeName(name);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找电影")
    public Film findById(@PathVariable String id) {
        return filmService.findById(id);
    }

    @PutMapping("")
    @ApiOperation(value = "更新电影")
    public void update(@RequestBody Film film) {
        filmService.update(film);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除电影")
    public void deleteById(@PathVariable String id) {
        filmService.deleteById(id);
    }


/**
 * 捕获controller异常
 * controller抛出异常执行下边的函数
 * 返回Response写入ApiResult
 */
@ResponseBody
@RestControllerAdvice
public class GlobalExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @ExceptionHandler(value = Exception.class)
    @DisableBaseResponse
    public Object handleException(Exception e) {
        if (e.getClass().equals(AccessDeniedException.class)){
            return new ResponseResult<>(403, "你没有访问权限");
        }
        logger.error(e.getMessage());
        return new ResponseResult<>(400, e.getMessage());
    }

}

@RestController
@Api(tags = "客服评价接口")

@RestController
@Api(tags = "电影排片场次接口")
@RequestMapping("/api/arrangement")
public class ArrangementController {

    @Resource
    private ArrangementService arrangementService;

    @Resource
    private FilmService filmService;

    @PostMapping("")
    @ApiOperation("新增电影场次")
    public void save(@RequestBody Arrangement arrangement) {
        arrangementService.save(arrangement);
    }

    @PutMapping("")
    @ApiOperation("修改排片信息")
    public Arrangement update(@RequestBody Arrangement arrangement) {
        return arrangementService.Update(arrangement);
    }

    @DeleteMapping("")
    @ApiOperation("根据id删除排片")
    public void delete(@RequestParam String id) {
        arrangementService.deleteById(id);
    }

    @GetMapping("")
    @ApiOperation("列出电影排片")
    public List<Arrangement> list() {
        return arrangementService.findAll();
    }

    @GetMapping("/{id}")
    @ApiOperation("查询拍片")
    public Map<String, Object> findById(@PathVariable String id) {
        HashMap<String, Object> map = new HashMap<>();
        Arrangement arrangement = arrangementService.findById(id);
        map.put("film", filmService.findById(arrangement.getFid()));
        map.put("arrangement", arrangement);
        return map;
    }


}

/**
 * Authorization 授权 发放token
 */
public class AuthorizationFilter extends BasicAuthenticationFilter {

    public AuthorizationFilter(AuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        //从Request Header 取出Token
        String token = request.getHeader(JwtTokenUtil.TOKEN_HEADER);

        //Token为空放行
        //如果接下来进入的URL不是公共的地址SpringSecurity会返回403的错误
        if (token == null || "null".equals(token)) {
            chain.doFilter(request, response);
            return;
        }

        //判断JWT Token是否过期
        if (JwtTokenUtil.isExpiration(token)) {
            ResponseUtil.writeJson(response, new ResponseResult<>(403, "令牌已过期, 请重新登录"));
            return;
        }

        //解析JWT获取用户信息
        String username = JwtTokenUtil.getUsername(token);
        ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<>();
        for (String role : JwtTokenUtil.getTokenRoles(token)) {
            authorities.add(new SimpleGrantedAuthority(role));

@RestController
@Api(tags = "电影接口")
@RequestMapping("/api/film")
public class FilmController {

    @Resource
    private FilmService filmService;

    @PostMapping("")
    @ApiOperation(value = "保存电影")
    public void save(@RequestBody Film film) {
        filmService.save(film);
    }

    @GetMapping("")
    @ApiOperation("列出所有电影")
    public List<Film> list(String region, String type) {
        if (region != null && type != null) {
            return filmService.findByRegionAndType(region, type);
        }
        return filmService.findAll();
    }

    @GetMapping("/hot/{limit}")
    @ApiOperation("获取热榜电影")
    public List<Film> listHots(@PathVariable Integer limit) {
        return filmService.findHots(limit);
    }

    @GetMapping("/name/{name}")
    @ApiOperation("搜索电影")
    public List<Film> search(@PathVariable String name) {
        return filmService.findLikeName(name);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找电影")
    public Film findById(@PathVariable String id) {
        return filmService.findById(id);
    }

@RestController
@Api(tags = "员工接口")
@RequestMapping("/api/worker")
public class WorkerController {

    @Resource
    private WorkerService workerService;

    @Resource
    private RoleService roleService;

    @PostMapping("/login")
    @ApiOperation("员工登录")
    public Map<String, Object> login(@RequestBody LoginDto dto) throws Exception {
        Worker worker = workerService.login(dto);
        Map<String, Object> map = new HashMap<>();
        //是否选择记住我
        long exp = dto.isRemember() ? JwtTokenUtil.REMEMBER_EXPIRATION_TIME : JwtTokenUtil.EXPIRATION_TIME;

        //查询登录的客服具有哪些权限
        List<String> roles = new ArrayList<>();
        //添加最基本的客服权限
        roles.add(Roles.ROLE_WORKER);

        for (Role role : roleService.listRolesByWorkerId(worker.getId())){
            roles.add(role.getValue());
        }
        map.put("token", JwtTokenUtil.createToken(dto.getUsername(), roles, exp));
        map.put("worker", worker);
        return map;
    }

    @PostMapping("")
    @ApiOperation("添加员工")
    public Worker create(@RequestBody Worker worker) throws Exception {
        return workerService.create(worker);
    }

    @GetMapping("")
    @ApiOperation("查询全部员工")
    public List<Worker> list(){
        return workerService.findAll();
    }

    @GetMapping("/{id}")
    public List<Poster> list(String status) {
        if (status != null) {
            return posterService.findByStatus(Boolean.parseBoolean(status));
        }
        return posterService.findAll();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(("删除海报"))
    public void delete(@PathVariable String id) {
        posterService.deleteById(id);
    }

    @DeleteMapping("")
    @ApiOperation(("删除所有海报"))
    public void deleteAll() {
        posterService.deleteAll();
    }

}

/**
 * 统一拦截Controller中所有方法的返回值
 * 封装后返回ResponseResult<T>
 */
@ControllerAdvice(basePackages = "com.movie.api")
public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {

    @Override
    public boolean supports(MethodParameter methodParameter, Class c) {
        //如果方法上带有DisableBaseResponse注解, 不处理返回false
        return !methodParameter.hasMethodAnnotation(DisableBaseResponse.class);
    }

    @Override
    public ResponseResult<Object> beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class aClass,
                                  ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
        if (o == null) {
            return new ResponseResult<>();
        }
        return new ResponseResult<>(o);
    }
public class OrderController {

    @Resource
    private OrderService orderService;

    @PostMapping("")
    @ApiOperation(value = "创建订单")
    public void save(@RequestBody Cart cart) throws Exception {
        orderService.create(cart);
    }

    @GetMapping("")
    @ApiOperation(value = "查询所有订单")
    public List<OrderVO> findAll() {
        return orderService.findAll();
    }

    @PutMapping("")
    @ApiOperation(value = "查询所有订单")
    public void update(@RequestBody Order order) {
        orderService.update(order);
    }

    @GetMapping("/user/{id}")
    @ApiOperation(value = "查询用户订单")
    public List<OrderVO> findByUser(@PathVariable String id) {
        return orderService.findByUser(id);
    }

    @GetMapping("/pay")
    @ApiOperation(value = "支付订单")
    public Order save(String id) throws Exception {
        return orderService.pay(id);
    }

}

@RestController
@Api(tags = "电影评价接口")
        filmService.deleteById(id);
    }

}

/**
 * 对工作人员的权限管理
 * 所有接口都需要管理员权限验证
 */
@RestController
@Api(tags = "权限接口")
@RequestMapping("/api/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/system")
    @ApiOperation("查看系统设置有哪些权限")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public String[] listSystemRoles() {
        return Roles.roles;
    }

    @PostMapping("")
    @ApiOperation("添加权限")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Role create(@RequestBody Role role) throws Exception {
        return roleService.create(role);
    }
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询员工")
    public Worker findById(@PathVariable String id){
        return workerService.findById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除员工")
    public void deleteById(@PathVariable String id){
        workerService.deleteById(id);
    }

    @PutMapping("")
    @ApiOperation("更新员工信息")
    public void update(@RequestBody Worker worker) throws Exception {
        workerService.update(worker);
    }

}

/**
 * Authorization 授权 发放token
 */
public class AuthorizationFilter extends BasicAuthenticationFilter {

    public AuthorizationFilter(AuthenticationManager authenticationManager) {
        super(authenticationManager);
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        //如果接下来进入的URL不是公共的地址SpringSecurity会返回403的错误
        if (token == null || "null".equals(token)) {
            chain.doFilter(request, response);
            return;
        }

        //判断JWT Token是否过期
        if (JwtTokenUtil.isExpiration(token)) {
            ResponseUtil.writeJson(response, new ResponseResult<>(403, "令牌已过期, 请重新登录"));
            return;
        }

        //解析JWT获取用户信息
        String username = JwtTokenUtil.getUsername(token);
        ArrayList<SimpleGrantedAuthority> authorities = new ArrayList<>();
        for (String role : JwtTokenUtil.getTokenRoles(token)) {
            authorities.add(new SimpleGrantedAuthority(role));
        }

        //向SpringSecurity的Context中加入认证信息
        SecurityContextHolder.getContext().setAuthentication(
                new UsernamePasswordAuthenticationToken(username, null, authorities));
        super.doFilterInternal(request, response, chain);
    }

}

@RestController
@Api(tags = "电影排片场次接口")
@RequestMapping("/api/arrangement")
/**
 * 对工作人员的权限管理
 * 所有接口都需要管理员权限验证
 */
@RestController
@Api(tags = "权限接口")
@RequestMapping("/api/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/system")
    @ApiOperation("查看系统设置有哪些权限")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public String[] listSystemRoles() {
        return Roles.roles;
    }

    @PostMapping("")
    @ApiOperation("添加权限")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Role create(@RequestBody Role role) throws Exception {
        return roleService.create(role);
    }

    @GetMapping("")
    @ApiOperation("查询员工的权限")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public List<Role> listByWorkerId(String wid) {
        return roleService.listRolesByWorkerId(wid);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除权限")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public void delete(@PathVariable String id) throws Exception {
        roleService.deleteById(id);
    }

}


    @GetMapping("")
    @ApiOperation(value = "获取图片")
    @PermitAll
    @DisableBaseResponse
    public void get(@RequestParam("id") String id, HttpServletResponse response) throws Exception {
        if ("".equals(id)) {
            return;
        }
        Upload upload = uploadMapper.selectById(id);
        if (upload == null) {
            throw new Exception("图片不存在");
        }
        byte[] data = upload.getBytes();
        response.setContentType("image/jpeg");
        response.setCharacterEncoding("UTF-8");
        OutputStream outputStream = response.getOutputStream();
        InputStream in = new ByteArrayInputStream(data);
        int len;
        byte[] buf = new byte[1024];
        while ((len = in.read(buf, 0, 1024)) != -1) {
            outputStream.write(buf, 0, len);
        }
        outputStream.close();
    }

}


    @GetMapping("/film/{fid}")
    @ApiOperation("查询某个电影的所有拍片")
    public ArrangementVO findByFilmId(@PathVariable String fid) {
        return arrangementService.findByFilmId(fid);
    }

}

@RestController
@Api(tags = "用户接口")
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Map<String, Object> login(@RequestBody LoginDto dto) throws Exception {
        User user = userService.login(dto);
        Map<String, Object> map = new HashMap<>();
        //是否选择记住我
        long exp = dto.isRemember() ? JwtTokenUtil.REMEMBER_EXPIRATION_TIME : JwtTokenUtil.EXPIRATION_TIME;
        List<String> roles = new ArrayList<>();
        roles.add(Roles.ROLE_USER);
        map.put("token", JwtTokenUtil.createToken(dto.getUsername(), roles, exp));
        map.put("user", user);
        return map;
    }

    @GetMapping("")
@ControllerAdvice(basePackages = "com.movie.api")
public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {

    @Override
    public boolean supports(MethodParameter methodParameter, Class c) {
        //如果方法上带有DisableBaseResponse注解, 不处理返回false
        return !methodParameter.hasMethodAnnotation(DisableBaseResponse.class);
    }

    @Override
    public ResponseResult<Object> beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class aClass,
                                  ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
        if (o == null) {
            return new ResponseResult<>();
        }
        return new ResponseResult<>(o);
    }

}

@RestController
@Api(tags = "留言接口")
@RequestMapping("/api/lm")
public class LeavingMessageController {

    @Resource
    private LeavingMessageService leavingMessageService;

    @PostMapping("")
    @ApiOperation(value = "新增留言接口")
    public void save(@RequestBody LeavingMessage leavingMessage) {
        leavingMessageService.save(leavingMessage);
    }

    @PutMapping("")
    @ApiOperation("回复留言")
    public void reply(@RequestBody LeavingMessage leavingMessage) {

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值