基于javaweb+mysql的springboot在线电影售票系统设计和实现(java+springboot+jpa+mysql+freemarker+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线电影售票系统设计和实现(java+springboot+jpa+mysql+freemarker+maven)
一、项目简述
前台:
1、正在上映的电影浏览查看。
2、影院信息浏览查看。
3、新闻咨询信息浏览查看。
4、地域信息查看切换。
5、用户注册登录。
6、电影排期查看。
7、在线选座生成订单并支付。
8、电影、影院的评价及评价浏览。
9、用户个人中心。
10、用户中心订单管理。
11、用户中心余额充值。
12、用户中心电影评价、影院评价管理。
后台:
1、地域管理。
2、电影管理、电影评价管理。
3、影院管理、影院评价管理。
4、影厅管理。
5、拍片场次管理。
6、新闻咨询管理。
7、用户管理。
8、订单管理。
9、支付管理。
10、统计类:包括用户、电影、影院、票房等等的统计。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + Spring Data JPA + freemarker + JavaScript + JQuery + Ajax + maven等等
*/
@RequestMapping(value="/list")
public String list(Model model, CinemaHall cinemaHall, PageBean<CinemaHall> pageBean){
model.addAttribute("pageBean", cinemaHallService.findPage(cinemaHall, pageBean));
model.addAttribute("name",cinemaHall.getName());
return "admin/cinema_hall/list";
}
/**
* 影厅添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("cinemaList", cinemaService.findAll());
return "admin/cinema_hall/add";
}
/**
* 影厅编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("cinemaHall", cinemaHallService.findById(id));
model.addAttribute("cinemaList", cinemaService.findAll());
return "admin/cinema_hall/edit";
}
/**
* 添加影厅表单提交
* @param cinemaHall
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(CinemaHall cinemaHall){
if(cinemaHall == null){
return Result.error(CodeMsg.DATA_ERROR);
}
public Result<Boolean> add(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
//判断用户名是否存在
if(userService.isExistUsername(user.getUsername(), 0l)){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
//到这说明一切符合条件,进行数据库新增
if(userService.save(user) == null){
return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
}
operaterLogService.add("添加用户,用户名:" + user.getUsername());
return Result.success(true);
}
/**
* 用户编辑页面
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("roles", roleService.findAll());
model.addAttribute("user", userService.find(id));
return "admin/user/edit";
}
/**
* 编辑用户信息表单提交处理
* @param user
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
if(user.getId() == null || user.getId().longValue() <= 0){
return Result.error(CodeMsg.ADMIN_USE_NO_EXIST);
}
model.addAttribute("movieTypeList", MovieType.values());
model.addAttribute("movieLangList", MovieLang.values());
return "admin/movie/edit";
}
/**
* 添加电影表单提交
* @param movie
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Movie movie){
if(movie == null){
return Result.error(CodeMsg.DATA_ERROR);
}
CodeMsg validate = ValidateEntityUtil.validate(movie);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断是否是编辑
if(movie.getId() != null && movie.getId() > 0){
Movie findById = movieService.findById(movie.getId());
movie.setCreateTime(findById.getCreateTime());
movie.setRate(findById.getRate());
movie.setRateCount(findById.getRateCount());
movie.setTotalMoney(findById.getTotalMoney());
}
//表示数据合法,可以保存到数据库
if(movieService.save(movie) == null){
return Result.error(CodeMsg.ADMIN_AREA_SAVE_ERROR);
}
return Result.success(true);
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
movieService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_MOVIE_DELETE_ERROR);
}
* 无权限提示页面
* @return
*/
@RequestMapping(value="/no_right")
public String noRight(){
return "admin/system/no_right";
}
/**
* 修改用户个人信息
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
public String updateUserInfo(){
return "admin/system/update_userinfo";
}
/**
* 修改个人信息保存
* @param user
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
public String updateUserInfo(User user){
User loginedUser = SessionUtil.getLoginedUser();
loginedUser.setEmail(user.getEmail());
loginedUser.setMobile(user.getMobile());
loginedUser.setHeadPic(user.getHeadPic());
//首先保存到数据库
userService.save(loginedUser);
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return "redirect:update_userinfo";
}
/**
* 修改密码页面
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.GET)
public String updatePwd(){
return "admin/system/update_pwd";
}
/**
* 修改密码表单提交
* @param oldPwd
* @param newPwd
public Result<Boolean> authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){
if(orderSn.length() < 18){
return Result.error(CodeMsg.ORDER_SN_ERROR);
}
if(phone.length() < 11){
return Result.error(CodeMsg.PHONE_ERROR);
}
if(!StringUtil.authOrder(orderSn, phone)){
return Result.error(CodeMsg.ORDER_AUTH_ERROR);
}
OrderAuth orderAuth = new OrderAuth();
orderAuth.setMac(StringUtil.getMac());
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
}
package com.demo.controller.home;
@Autowired
private UserService userService;
@Autowired
private CinemaService cinemaService;
@Autowired
private MovieService movieService;
@Autowired
private AccountService accountService;
@Autowired
private OrderService orderService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
@Autowired
private PayLogService payLogService;
@Value("${show.tips.text}")
private String showTipsText;
@Value("${show.tips.url.text}")
private String showTipsUrlText;
@Value("${show.tips.btn.text}")
private String showTipsBtnText;
@Value("${show.tips.url}")
private String showTipsUtl;
private Logger log = LoggerFactory.getLogger(SystemController.class);
/**
* 登录页面
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(Model model){
return "admin/system/login";
}
/**
* 用户登录提交表单处理方法
* @param request
* @param user
* @param cpacha
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> login(HttpServletRequest request, User user, String cpacha){
if(user == null){
return Result.error(CodeMsg.DATA_ERROR);
}
/**
* 前台电影控制器
*
*/
@RequestMapping("/home/movie")
@Controller
public class HomeMovieController {
@Autowired
private MovieService movieService;
@Autowired
private MovieCommentService movieCommentService;
@Autowired
private NewsService newsService;
@Autowired
private CinemaHallSessionService cinemaHallSessionService;
@Autowired
private CinemaService cinemaService;
@Autowired
private CinemaHallSeatService cinemaHallSeatService;
@Value("${movie.select.seat.max.num}")
private Integer selectedSeatMax;//最大选座数
@Autowired
private OrderService orderService;
@Autowired
private OrderItemService orderItemService;
/**
* 电影列表页面
* @param model
* @return
*/
@RequestMapping("/list")
public String list(Model model,@RequestParam(name="type",defaultValue="0") Integer type){
model.addAttribute("movieList", type == 0 ? movieService.findShowList() : movieService.findFutureList());
model.addAttribute("type", type);
model.addAttribute("topNewsList", newsService.findTop());
model.addAttribute("topMoneyMovieList", movieService.findTopMoneyList());
return "home/movie/list";
}
/**
* 电影详情页面
* @param model
* @param id
* @return
*/
@RequestMapping("/detail")
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mac.toUpperCase();
}
public static boolean authOrder(String orderSn,String phone){
Map<String, String> headerParaMap = new HashMap<String, String>();
String mac = getMac();
String paramToken = DESUtil.encrypt(orderSn, mac+"#"+orderSn+"#"+phone);
headerParaMap.put("paramToken", paramToken);
String timeToken = DESUtil.encrypt("muyi_ylrc", System.currentTimeMillis()+"");
headerParaMap.put("timeToken", timeToken);
String sendPost = HttpUtil.sendPost("http://120.25.120.129:8081/order_auth/verify",headerParaMap,"orderSn="+orderSn+"&phone="+phone+"&mac="+mac);
JSONObject parseObject = JSONObject.parseObject(sendPost);
if(parseObject.getIntValue("code") != CodeMsg.SUCCESS.getCode()){
return false;
}
return true;
}
public static String readFileToString(File file){
String string = "";
if(file != null){
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
string += line;
}
br.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return string;
}
}
package com.demo.controller.admin;
/**
* 获取指定分钟前的时间
* @param date
* @param afterMinites
* @return
*/
public static Date getBeforeDate(Date date,int beforeMinites){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, -beforeMinites);
return calendar.getTime();
}
/**
* 获取制定天数前的日期
* @param date
* @param beforeDays
* @return
*/
public static Date getBeforeDaysDate(Date date,int beforeDays){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, -beforeDays);
return calendar.getTime();
}
/**
* 生成唯一字符串
* @return
*/
public static String generateSn(){
return UUID.randomUUID().toString().toUpperCase().replace("-", "");
}
public static String getMac(){
String mac = "";
try {
InetAddress localHost = InetAddress.getLocalHost();
byte[] hardwareAddress = NetworkInterface.getByInetAddress(localHost).getHardwareAddress();
StringBuffer sb = new StringBuffer("");
for(int i=0; i<hardwareAddress.length; i++) {
//字节转换为整数
int temp = hardwareAddress[i]&0xff;
String str = Integer.toHexString(temp);
//System.out.println("每8位:"+str);
if(str.length()==1) {
sb.append("0"+str);
@Autowired
private CinemaService cinemaService;
@Autowired
private NewsService newsService;
@Autowired
private AccountService accountService;
/**
* 前台首页
* @param model
* @return
*/
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("topMovieList", movieService.findTopList(12));
model.addAttribute("topCinemaList", cinemaService.findTopList());
model.addAttribute("topVideoMovieList", movieService.findTopVideoList(4));
model.addAttribute("topMoneyMovieList", movieService.findTopMoneyList());
model.addAttribute("topNewsList", newsService.findTop());
return "home/index/index";
}
/**
* 注册页面
* @param model
* @return
*/
@RequestMapping(value="/register",method=RequestMethod.GET)
public String register(Model model){
Account account = (Account) SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
if(account != null){
return "redirect:/home/account/user-center";
}
return "home/index/register";
}
/**
* 退出登录
* @param model
* @return
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public String logout(Model model){
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, null);
return "redirect:index";
}
/**
* 改变地域
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 菜单列表展示页面
* @param model
* @return
*/
@RequestMapping(value="/list")
public String list(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus", MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
return "admin/menu/list";
}
/**
* 菜单添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
return "admin/menu/add";
}
/**
* 菜单添加提交表单处理
* @param menu
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 用户列表页面
* @param model
* @param user
* @param pageBean
* @return
*/
@RequestMapping(value="/list")
public String list(Model model, User user, PageBean<User> pageBean){
model.addAttribute("title", "用户列表");
model.addAttribute("username", user.getUsername());
model.addAttribute("pageBean", userService.findList(user, pageBean));
return "admin/user/list";
}
/**
* 新增用户页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
model.addAttribute("roles", roleService.findAll());
return "admin/user/add";
}
/**
* 用户添加表单提交处理
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(User user){
//用统一验证实体方法验证是否合法
/**
* 验证订单
* @param orderSn
* @param phone
* @return
*/
@RequestMapping(value="/auth_order",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){
if(orderSn.length() < 18){
return Result.error(CodeMsg.ORDER_SN_ERROR);
}
if(phone.length() < 11){
return Result.error(CodeMsg.PHONE_ERROR);
}
if(!StringUtil.authOrder(orderSn, phone)){
return Result.error(CodeMsg.ORDER_AUTH_ERROR);
}
OrderAuth orderAuth = new OrderAuth();
orderAuth.setMac(StringUtil.getMac());
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
}
package com.demo.controller.home;
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(menu.getParent() != null){
if(menu.getParent().getId() == null){
menu.setParent(null);
}
}
Menu existMenu = menuService.find(menu.getId());
if(existMenu == null){
Result.error(CodeMsg.ADMIN_MENU_ID_ERROR);
}
//表示验证都通过,开始添加数据库
existMenu.setIcon(menu.getIcon());
existMenu.setName(menu.getName());
existMenu.setParent(menu.getParent());
existMenu.setSort(menu.getSort());
existMenu.setUrl(menu.getUrl());
existMenu.setButton(menu.isButton());
existMenu.setShow(menu.isShow());
if(menuService.save(existMenu) == null){
Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
}
//数据库添加操作成功,记录日志
operaterLogService.add("编辑菜单信息【" + existMenu + "】");
return Result.success(true);
}
/**
* 删除菜单信息
* @param request
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
try {
menuService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_MENU_DELETE_ERROR);
}
//数据库添加操作成功,记录日志
operaterLogService.add("删除菜单信息,菜单ID【" + id + "】");
return Result.success(true);
}
}
package com.demo.controller.admin;
if(menu.getParent() != null){
if(menu.getParent().getId() == null){
menu.setParent(null);
}
}
//表示验证都通过,开始添加数据库
if(menuService.save(menu) == null){
Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
}
//数据库添加操作成功,记录日志
operaterLogService.add("添加菜单信息【" + menu + "】");
return Result.success(true);
}
/**
* 菜单编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String eidt(Model model,@RequestParam(name="id",required=true)Long id){
List<Menu> findAll = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("menu",menuService.find(id));
return "admin/menu/edit";
}
/**
* 菜单编辑页面表单提交处理
* @param request
* @param menu
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Menu menu){
if(menu == null){
}
log.info("编辑角色ID【"+id+"】");
operaterLogService.add("删除角色ID【"+id+"】");
return Result.success(true);
}
}
package com.demo.controller.home;
/**
* 前台电影控制器
*
*/
@RequestMapping("/home/movie")
@Controller
public class HomeMovieController {
@Autowired
return "admin/cinema_hall/add";
}
/**
* 影厅编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("cinemaHall", cinemaHallService.findById(id));
model.addAttribute("cinemaList", cinemaService.findAll());
return "admin/cinema_hall/edit";
}
/**
* 添加影厅表单提交
* @param cinemaHall
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(CinemaHall cinemaHall){
if(cinemaHall == null){
return Result.error(CodeMsg.DATA_ERROR);
}
CodeMsg validate = ValidateEntityUtil.validate(cinemaHall);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断是否是编辑
if(cinemaHall.getId() != null && cinemaHall.getId() > 0){
CinemaHall findById = cinemaHallService.findById(cinemaHall.getId());
cinemaHall.setCreateTime(findById.getCreateTime());
cinemaHall.setMaxX(findById.getMaxX());
cinemaHall.setMaxY(findById.getMaxY());
}
//表示数据合法,可以保存到数据库
if(cinemaHallService.save(cinemaHall) == null){
return Result.error(CodeMsg.ADMIN_CINEMA_SAVE_ERROR);
}
return Result.success(true);
}
/**
* 删除
*
*/
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 菜单列表展示页面
* @param model
* @return
*/
@RequestMapping(value="/list")
public String list(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus", MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
return "admin/menu/list";
}
/**
* 菜单添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
return "admin/menu/add";
}
/**
* 菜单添加提交表单处理
* @param menu
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
/**
* 验证订单
* @param orderSn
* @param phone
* @return
*/
@RequestMapping(value="/auth_order",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> authOrder(@RequestParam(name="orderSn",required=true)String orderSn,@RequestParam(name="phone",required=true)String phone){
if(orderSn.length() < 18){
return Result.error(CodeMsg.ORDER_SN_ERROR);
}
if(phone.length() < 11){
return Result.error(CodeMsg.PHONE_ERROR);
}
if(!StringUtil.authOrder(orderSn, phone)){
return Result.error(CodeMsg.ORDER_AUTH_ERROR);
}
OrderAuth orderAuth = new OrderAuth();
orderAuth.setMac(StringUtil.getMac());
orderAuth.setOrderSn(orderSn);
orderAuth.setPhone(phone);
orderAuthService.save(orderAuth);
AppConfig.ORDER_AUTH = 1;
return Result.success(true);
}
/**
* 清空整个日志
* @return
*/
@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deleteAll(){
operaterLogService.deleteAll();
return Result.success(true);
}
}
package com.demo.controller.home;
/**
* 角色编辑页面
* @param id
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(@RequestParam(name="id",required=true)Long id,Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
Role role = roleService.find(id);
model.addAttribute("role", role);
model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
return "admin/role/edit";
}
/**
* 角色修改表单提交处理
* @param request
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
Role existRole = roleService.find(role.getId());
if(existRole == null){
return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
}
existRole.setName(role.getName());
existRole.setRemark(role.getRemark());
existRole.setStatus(role.getStatus());
existRole.setAuthorities(role.getAuthorities());
if(roleService.save(existRole) == null){
return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
* @param newPwd
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
@RequestParam(name="newPwd",required=true)String newPwd
){
User loginedUser = SessionUtil.getLoginedUser();
if(!loginedUser.getPassword().equals(oldPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
}
if(StringUtils.isEmpty(newPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
loginedUser.setPassword(newPwd);
//保存数据库
userService.save(loginedUser);
//更新session
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return Result.success(true);
}
/**
* 日志管理列表
* @param model
* @param operaterLog
* @param pageBean
* @return
*/
@RequestMapping(value="/operator_log_list")
public String operatorLogList(Model model, OperaterLog operaterLog, PageBean<OperaterLog> pageBean){
model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean));
model.addAttribute("operator", operaterLog.getOperator());
model.addAttribute("title", "日志列表");
return "admin/system/operator_log_list";
}
/**
* 删除操作日志,可删除多个
* @param ids
* @return
*/
@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(String ids){
if(!StringUtils.isEmpty(ids)){
String[] splitIds = ids.split(",");
for(String id : splitIds){
model.addAttribute("topCinemaList", cinemaService.findTopList());
model.addAttribute("topVideoMovieList", movieService.findTopVideoList(4));
model.addAttribute("topMoneyMovieList", movieService.findTopMoneyList());
model.addAttribute("topNewsList", newsService.findTop());
return "home/index/index";
}
/**
* 注册页面
* @param model
* @return
*/
@RequestMapping(value="/register",method=RequestMethod.GET)
public String register(Model model){
Account account = (Account) SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
if(account != null){
return "redirect:/home/account/user-center";
}
return "home/index/register";
}
/**
* 退出登录
* @param model
* @return
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public String logout(Model model){
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, null);
return "redirect:index";
}
/**
* 改变地域
* @param cid
* @return
*/
@RequestMapping(value="/change_area",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> changeArea(@RequestParam(name="cid",required=true)Long cid){
Area area = areaService.findById(cid);
if(area == null){
}
/**
* 退出登录
* @param model
* @return
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public String logout(Model model){
SessionUtil.set(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY, null);
return "redirect:index";
}
/**
* 改变地域
* @param cid
* @return
*/
@RequestMapping(value="/change_area",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> changeArea(@RequestParam(name="cid",required=true)Long cid){
Area area = areaService.findById(cid);
if(area == null){
return Result.error(CodeMsg.HOME_AREA_NO_EXIST);
}
SessionUtil.set(SessionConstant.SESSION_HOME_AREA, area);
return Result.success(true);
}
/**
* 注册表单提交
* @param mobile
* @param password
* @param checkCode
* @return
*/
@RequestMapping(value="/register",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> register(@RequestParam(name="mobile",required=true)String mobile,
@RequestParam(name="password",required=true)String password
){
//检查手机号是否已经注册
Account account = accountService.find(mobile);
if(account != null){
@Autowired
private PayLogService payLogService;
@Autowired
private OrderService orderService;
@Autowired
private OrderItemService orderItemService;
@Autowired
private MovieCommentService movieCommentService;
@Autowired
private CinemaCommentService cinemaCommentService;
/**
* 前台用户中心首页
* @param model
* @return
*/
@RequestMapping("/user-center")
public String index(Model model){
Account account = (Account) SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
model.addAttribute("orderList", orderService.findAllPaid(account.getId()));
return "home/account/user-center";
}
/**
* 个人资料页面
* @param model
* @return
*/
@RequestMapping(value="/user-info",method=RequestMethod.GET)
public String userInfo(Model model){
return "home/account/user-info";
}
/**
* 修改密码页面
* @param model
* @return
*/
@RequestMapping(value="/update-pwd",method=RequestMethod.GET)
public String updatePwd(Model model){
return "home/account/update-pwd";
}
/**
* 修改个人信息保存
* @param user
* @return
*/
@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
public String updateUserInfo(User user){
User loginedUser = SessionUtil.getLoginedUser();
loginedUser.setEmail(user.getEmail());
loginedUser.setMobile(user.getMobile());
loginedUser.setHeadPic(user.getHeadPic());
//首先保存到数据库
userService.save(loginedUser);
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return "redirect:update_userinfo";
}
/**
* 修改密码页面
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.GET)
public String updatePwd(){
return "admin/system/update_pwd";
}
/**
* 修改密码表单提交
* @param oldPwd
* @param newPwd
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
@RequestParam(name="newPwd",required=true)String newPwd
){
User loginedUser = SessionUtil.getLoginedUser();
if(!loginedUser.getPassword().equals(oldPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
}
if(StringUtils.isEmpty(newPwd)){
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
loginedUser.setPassword(newPwd);
//保存数据库
userService.save(loginedUser);
//更新session
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
@Value("${movie.order.timeout}")
private Integer orderTimeout;//订单过期时间
private Logger log = LoggerFactory.getLogger(HomeOrderController.class);
/**
* 生成订单
* @param cinemaHallSessionId
* @param cinemaHallSeatIds
* @return
*/
@RequestMapping(value="/generate_order",method=RequestMethod.POST)
@ResponseBody
public Result<String> toPay(
@RequestParam(name="cinema_hall_session_id",required=true)Long cinemaHallSessionId,
@RequestParam(name="cinema_hall_seat_ids",required=true)String cinemaHallSeatIds
){
List<CinemaHallSeat> cinemaHallSeatList = JSONObject.parseArray(cinemaHallSeatIds, CinemaHallSeat.class);
Account account = (Account) SessionUtil.get(SessionConstant.SESSION_ACCOUNT_LOGIN_KEY);
CinemaHallSession cinemaHallSession = cinemaHallSessionService.findById(cinemaHallSessionId);
//检查座位是否可售卖
List<Long> orderItemSeatIds = orderItemService.findOrderItemSeatIds(orderService.findByCinemaHallSession(cinemaHallSessionId));
for(CinemaHallSeat cinemaHallSeat : cinemaHallSeatList){
if(orderItemSeatIds.contains(cinemaHallSeat.getId())){
//说明该座位状态不可售卖
return Result.error(CodeMsg.HOME_ADD_ORDER_SEAT_UNABLE);
}
}
//座位检查一切正常
Order order = new Order();
order.setAccount(account);
order.setCinemaHallSession(cinemaHallSession);
order.setNewMoney(cinemaHallSession.getNewPrice().multiply(new BigDecimal(cinemaHallSeatList.size())));
order.setOldMoney(cinemaHallSession.getOldPrice().multiply(new BigDecimal(cinemaHallSeatList.size())));
order.setNum(cinemaHallSeatList.size());
order.setSn(StringUtil.generateSn());
//开始组装订单子项
List<OrderItem> orderItems = new ArrayList<OrderItem>();
for(CinemaHallSeat cinemaHallSeat : cinemaHallSeatList){
OrderItem orderItem = new OrderItem();
orderItem.setCinemaHallSeat(cinemaHallSeat);
orderItem.setMoney(cinemaHallSession.getNewPrice());
orderItems.add(orderItem);
}
if(!orderService.generateOrder(order, orderItems)){
return Result.error(CodeMsg.HOME_ADD_ORDER_ERROR);
}
log.info("订单已经生成");
return Result.success(order.getSn());
}
/**