diff --git a/src/main/java/com/example/hotel/config/MvcConfig.java b/src/main/java/com/example/hotel/config/MvcConfig.java deleted file mode 100755 index efe9f8c..0000000 --- a/src/main/java/com/example/hotel/config/MvcConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.example.hotel.config; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.config.annotation.*; -import org.springframework.web.servlet.i18n.SessionLocaleResolver; - -import java.util.Locale; - -/** - * 拦截器,资源路径配置 - */ -@Slf4j -@Configuration -@EnableWebMvc -@ComponentScan(basePackages = "com.example.hotel.controller") -@PropertySource(value = "classpath:application.yaml", ignoreResourceNotFound = true, encoding = "UTF-8") -public class MvcConfig implements WebMvcConfigurer { - - - /** - * 配置静态资源路径 - * - * @param registry registry - */ - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/static/**") - .addResourceLocations("classpath:/static/"); - registry.addResourceHandler("/**") - .addResourceLocations("classpath:/templates/themes/") - .addResourceLocations("classpath:/robots.txt"); - registry.addResourceHandler("/upload/**") - .addResourceLocations("file:///" + System.getProperties().getProperty("user.home") + "/sens/upload/"); - registry.addResourceHandler("/favicon.ico") - .addResourceLocations("classpath:/static/images/favicon.ico"); - } - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowCredentials(true) - .allowedHeaders("*") - .allowedOrigins("*") - .allowedMethods("*"); - } - - @Bean - public LocaleResolver localeResolver() { - SessionLocaleResolver slr = new SessionLocaleResolver(); - slr.setDefaultLocale(Locale.CHINA); - return slr; - } -} diff --git a/src/main/java/com/example/hotel/config/mybatisplus/MybatisPlusConfig.java b/src/main/java/com/example/hotel/config/mybatisplus/MybatisPlusConfig.java deleted file mode 100644 index 11ecfd6..0000000 --- a/src/main/java/com/example/hotel/config/mybatisplus/MybatisPlusConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.example.hotel.config.mybatisplus; - -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - - -/** - * @author 言曌 - * @date 2018/12/22 下午1:49 - */ - -@Configuration -public class MybatisPlusConfig { - - /*** - * plus 的性能优化 - * @return - */ - @Bean - public PerformanceInterceptor performanceInterceptor() { - PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor(); - /**/ - performanceInterceptor.setMaxTime(1000); - /**/ - performanceInterceptor.setFormat(true); - return performanceInterceptor; - } - - /** - * mybatis-plus分页插件 - */ - @Bean - public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); - } - - - -} diff --git a/src/main/java/com/example/hotel/config/properties/IgnoredUrlsProperties.java b/src/main/java/com/example/hotel/config/properties/IgnoredUrlsProperties.java deleted file mode 100755 index 5d06a4f..0000000 --- a/src/main/java/com/example/hotel/config/properties/IgnoredUrlsProperties.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.example.hotel.config.properties; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author example - */ -@Data -@Configuration -@ConfigurationProperties(prefix = "ignored") -public class IgnoredUrlsProperties { - - private List urls = new ArrayList<>(); -} diff --git a/src/main/java/com/example/hotel/config/shiro/MyRealm.java b/src/main/java/com/example/hotel/config/shiro/MyRealm.java deleted file mode 100644 index 4c5ccc0..0000000 --- a/src/main/java/com/example/hotel/config/shiro/MyRealm.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.example.hotel.config.shiro; - -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.lang.Validator; -import com.example.hotel.common.constant.CommonConstant; -import com.example.hotel.entity.Permission; -import com.example.hotel.entity.Role; -import com.example.hotel.service.PermissionService; -import com.example.hotel.service.RoleService; -import com.example.hotel.service.UserService; -import com.example.hotel.entity.User; -import com.example.hotel.enums.CommonParamsEnum; -import com.example.hotel.enums.TrueFalseEnum; -import com.example.hotel.enums.UserStatusEnum; -import com.example.hotel.util.RegexUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.apache.shiro.authc.*; -import org.apache.shiro.authz.AuthorizationInfo; -import org.apache.shiro.authz.SimpleAuthorizationInfo; -import org.apache.shiro.realm.AuthorizingRealm; -import org.apache.shiro.subject.PrincipalCollection; -import org.apache.shiro.util.ByteSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; - -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - -@Slf4j -public class MyRealm extends AuthorizingRealm { - - @Autowired - @Lazy - private UserService userService; - - @Autowired - @Lazy - private RoleService roleService; - - @Autowired - @Lazy - private PermissionService permissionService; - - - /** - * 认证信息(身份验证) Authentication 是用来验证用户身份 - */ - @Override - protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { - log.info("认证-->MyShiroRealm.doGetAuthenticationInfo()"); - //1.验证手机号 - User user; - String account = (String) token.getPrincipal(); - if (RegexUtil.isIdCard(account)) { - user = userService.findByIdCard(account); - } else { - user = userService.findByUserName(account); - } - if (user == null) { - //用户不存在 - log.info("用户不存在! 登录名:{}, 密码:{}", account, token.getCredentials()); - return null; - } - Role role = roleService.findByUserId(user.getId()); - if (role != null) { - user.setRole(role.getRole()); - } - - - //2.判断账号是否被封号 - if (!Objects.equals(user.getStatus(), UserStatusEnum.NORMAL.getCode())) { - throw new LockedAccountException("账号被封禁"); - } - - //3.封装authenticationInfo,准备验证密码 - SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( - user, // 手机号 - user.getUserPass(), // 密码 - ByteSource.Util.bytes(CommonConstant.PASSWORD_SALT), // 盐 - getName() // realm name - ); - System.out.println("realName:" + getName()); - return authenticationInfo; - } - - - @Override - protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { - - SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); - User user = (User) principals.getPrimaryPrincipal(); - - Role role = roleService.findByRoleId(user.getId()); - - authorizationInfo.addRole(role.getRole()); - List permissions = permissionService.listPermissionsByRoleId(role.getId()); - //把权限的URL全部放到authorizationInfo中去 - Set urls = permissions.stream().map(p -> p.getUrl()).collect(Collectors.toSet()); - authorizationInfo.addStringPermissions(urls); - - return authorizationInfo; - } -} diff --git a/src/main/java/com/example/hotel/config/shiro/ShiroConfig.java b/src/main/java/com/example/hotel/config/shiro/ShiroConfig.java deleted file mode 100644 index 9716ccf..0000000 --- a/src/main/java/com/example/hotel/config/shiro/ShiroConfig.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.example.hotel.config.shiro; - -import at.pollux.thymeleaf.shiro.dialect.ShiroDialect; -import com.example.hotel.config.properties.IgnoredUrlsProperties; -import org.apache.shiro.authc.credential.AllowAllCredentialsMatcher; -import org.apache.shiro.authc.credential.HashedCredentialsMatcher; -import org.apache.shiro.mgt.SecurityManager; -import org.apache.shiro.spring.web.ShiroFilterFactoryBean; -import org.apache.shiro.web.mgt.DefaultWebSecurityManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.servlet.Filter; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - - -@Configuration -public class ShiroConfig { - - @Bean - public ShiroDialect shiroDialect() { - return new ShiroDialect(); - } - - @Bean - IgnoredUrlsProperties getIgnoredUrlsProperties() { - return new IgnoredUrlsProperties(); - } - - @Bean - public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { - ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); - shiroFilterFactoryBean.setSecurityManager(securityManager); - //自定义拦截器 - Map filtersMap = new LinkedHashMap(); - //访问权限配置 - filtersMap.put("requestURL", getURLPathMatchingFilter()); - shiroFilterFactoryBean.setFilters(filtersMap); - - //拦截器. - Map filterChainDefinitionMap = new LinkedHashMap(); - // 配置不会被拦截的链接 顺序判断 - List urls = getIgnoredUrlsProperties().getUrls(); - for (String url : urls) { - filterChainDefinitionMap.put(url, "anon"); - } - filterChainDefinitionMap.put("/admin", "authc"); - filterChainDefinitionMap.put("/admin/**", "requestURL"); - filterChainDefinitionMap.put("/**", "anon"); - - shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); - - - // 如果不设置默认会自动寻找Web工程根目录下的"/login"页面 - shiroFilterFactoryBean.setLoginUrl("/"); - // 登录成功后要跳转的链接 - shiroFilterFactoryBean.setSuccessUrl("/"); - //未授权界面; - shiroFilterFactoryBean.setUnauthorizedUrl("/403"); - - return shiroFilterFactoryBean; - - } - - @Bean - public SecurityManager securityManager() { - DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); - securityManager.setRealm(myRealm()); - return securityManager; - } - - - @Bean - public MyRealm myRealm() { - MyRealm normalRealm = new MyRealm(); - normalRealm.setCredentialsMatcher(hashedCredentialsMatcher()); - return normalRealm; - } - - /** - * 访问 权限 拦截器 - * - * @return - */ - public URLPathMatchingFilter getURLPathMatchingFilter() { - return new URLPathMatchingFilter(); - } - - /** - * MD5加盐加密十次 - * - * @return - */ - @Bean - public HashedCredentialsMatcher hashedCredentialsMatcher() { - HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(); - //散列算法:这里使用MD5算法; - hashedCredentialsMatcher.setHashAlgorithmName("md5"); - //散列的次数,md5("") - hashedCredentialsMatcher.setHashIterations(10); - return hashedCredentialsMatcher; - } - - @Bean - public AllowAllCredentialsMatcher allowAllCredentialsMatcher() { - return new AllowAllCredentialsMatcher(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/example/hotel/config/shiro/URLPathMatchingFilter.java b/src/main/java/com/example/hotel/config/shiro/URLPathMatchingFilter.java deleted file mode 100644 index f9d6930..0000000 --- a/src/main/java/com/example/hotel/config/shiro/URLPathMatchingFilter.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.example.hotel.config.shiro; - -import com.alibaba.fastjson.JSONObject; -import com.example.hotel.service.PermissionService; -import com.example.hotel.util.SpringUtil; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.web.filter.PathMatchingFilter; -import org.apache.shiro.web.util.WebUtils; - -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * URL拦截器 - */ -public class URLPathMatchingFilter extends PathMatchingFilter { - - - PermissionService permissionService = null; - private PermissionService permissionService() { - if (permissionService == null) { - permissionService = (PermissionService) SpringUtil.getBean("permissionServiceImpl"); - } - return permissionService; - } - - @Override - protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { - //请求的url - String requestURL = getPathWithinApplication(request); - System.out.println("请求的url :" + requestURL); - Subject subject = SecurityUtils.getSubject(); - if (!subject.isAuthenticated()) { - // 如果没有登录, 进入登录流程 - WebUtils.issueRedirect(request, response, "/"); - return false; - } - - //从session里读取当前用户的权限URL列表 - Set urls = (Set) subject.getSession().getAttribute("permissionUrls"); - if (urls.contains(requestURL)) { - return true; - } - - //没有权限 - if (isAjax((HttpServletRequest) request)) { - response.setCharacterEncoding("utf-8"); - response.setContentType("application/json; charset=utf-8"); - PrintWriter writer = response.getWriter(); - Map map = new HashMap<>(); - map.put("code", 0); - map.put("msg", "没有权限访问"); - writer.write(JSONObject.toJSONString(map)); - } else { - WebUtils.issueRedirect(request, response, "/403"); - } - - return false; - } - - - public static boolean isAjax(HttpServletRequest httpRequest) { - return (httpRequest.getHeader("X-Requested-With") != null - && "XMLHttpRequest" - .equals(httpRequest.getHeader("X-Requested-With").toString())); - } - -} \ No newline at end of file diff --git a/src/main/java/com/example/hotel/controller/admin/AdminController.java b/src/main/java/com/example/hotel/controller/admin/AdminController.java deleted file mode 100644 index 4c0621d..0000000 --- a/src/main/java/com/example/hotel/controller/admin/AdminController.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.example.hotel.entity.Permission; -import com.example.hotel.entity.Role; -import com.example.hotel.entity.User; -import com.example.hotel.service.PermissionService; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.service.RoleService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -/** - *
- *     后台首页控制器
- * 
- */ -@Slf4j -@Controller -@RequestMapping(value = "/admin") -public class AdminController extends BaseController { - - @Autowired - private PermissionService permissionService; - - @Autowired - private RoleService roleService; - - /** - * 请求后台页面 - * - * @param model model - * @return 模板路径admin/admin_index - */ - @GetMapping - public String index(Model model) { -// return "admin/admin_index"; - return "redirect:/admin/order"; - } - - - /** - * 获得当前用户的菜单 - * - * @return - */ - @GetMapping(value = "/currentMenus") - @ResponseBody - public JsonResult getMenu() { - Long userId = getLoginUserId(); - List permissions = permissionService.findPermissionTreeByUserIdAndResourceType(userId, "menu"); - return JsonResult.success("", permissions); - } - - /** - * 获得当前登录用户 - */ - @GetMapping(value = "/currentUser") - @ResponseBody - public JsonResult currentUser() { - User user = getLoginUser(); - if (user != null) { - return JsonResult.success("", user); - } - return JsonResult.error("用户未登录"); - } - - /** - * 获得当前用户角色编码 - */ - @GetMapping(value = "/currentRole") - @ResponseBody - public JsonResult currentRole() { - Role role = roleService.findByUserId(getLoginUserId()); - if (role == null) { - return JsonResult.error("用户未登录或无角色"); - } - return JsonResult.success("", role.getRole()); - } - -} diff --git a/src/main/java/com/example/hotel/controller/admin/AttachmentController.java b/src/main/java/com/example/hotel/controller/admin/AttachmentController.java deleted file mode 100755 index b3230fb..0000000 --- a/src/main/java/com/example/hotel/controller/admin/AttachmentController.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.util.FileUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.util.HashMap; -import java.util.Map; - - -/** - *
- *     后台附件控制器
- * 
- * - * @author : saysky - * @date : 2017/12/19 - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/file") -public class AttachmentController extends BaseController { - - - /** - * 上传文件 - * - * @param file file - * @return Map - */ - @PostMapping(value = "/upload", produces = {"application/json;charset=UTF-8"}) - @ResponseBody - public Map uploadFile(@RequestParam("file") MultipartFile file) { - Map map = new HashMap<>(1); - String path = FileUtil.upload(file); - map.put("link", path); - return map; - } - - -} diff --git a/src/main/java/com/example/hotel/controller/admin/CategoryController.java b/src/main/java/com/example/hotel/controller/admin/CategoryController.java deleted file mode 100755 index 4a767e2..0000000 --- a/src/main/java/com/example/hotel/controller/admin/CategoryController.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.entity.Category; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.service.CategoryService; -import com.example.hotel.util.PageUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -/** - *
- *     后台分类管理控制器
- * 
- * - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/category") -public class CategoryController extends BaseController { - - @Autowired - private CategoryService categoryService; - - - /** - * 查询所有分类并渲染category页面 - * - * @return 模板路径admin/admin_category - */ - @GetMapping - public String categories(@RequestParam(value = "page", defaultValue = "0") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "cateSort") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, Model model) { - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - Page categoryPage = categoryService.findAll(page); - model.addAttribute("categories", categoryPage.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - return "admin/admin_category"; - } - - /** - * 新增/修改分类目录 - * - * @param category category对象 - * @return 重定向到/admin/category - */ - @PostMapping(value = "/save") - @ResponseBody - public JsonResult saveCategory(@ModelAttribute Category category) { - categoryService.insertOrUpdate(category); - return JsonResult.success("保存成功"); - } - - /** - * 删除分类 - * - * @param cateId 分类Id - * @return JsonResult - */ - @DeleteMapping(value = "/delete") - @ResponseBody - public JsonResult checkDelete(@RequestParam("id") Long cateId) { - //1.判断这个分类有客房 - Integer count = categoryService.countPostByCateId(cateId); - if (count != 0) { - return JsonResult.error("该分类已经有了客房,无法删除"); - } - categoryService.delete(cateId); - return JsonResult.success("删除成功"); - } - - - /** - * 跳转到修改页面 - * - * @param cateId cateId - * @param model model - * @return 模板路径admin/admin_category - */ - @GetMapping(value = "/edit") - public String toEditCategory(Model model, - @RequestParam(value = "page", defaultValue = "0") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "cateSort") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, - @RequestParam("id") Long cateId) { - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - - //更新的分类 - Category category = categoryService.get(cateId); - if (category == null) { - return this.renderNotFound(); - } - model.addAttribute("updateCategory", category); - - // 所有分类 - Page categoryPage = categoryService.findAll(page); - model.addAttribute("categories", categoryPage.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - return "admin/admin_category"; - } -} diff --git a/src/main/java/com/example/hotel/controller/admin/OrderController.java b/src/main/java/com/example/hotel/controller/admin/OrderController.java deleted file mode 100755 index 05ad0ff..0000000 --- a/src/main/java/com/example/hotel/controller/admin/OrderController.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.dto.QueryCondition; -import com.example.hotel.entity.Order; -import com.example.hotel.enums.OrderStatusEnum; -import com.example.hotel.service.OrderService; -import com.example.hotel.service.RecordService; -import com.example.hotel.util.DateUtil; -import com.example.hotel.util.PageUtil; -import com.example.hotel.util.RegexUtil; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.weaver.ast.Or; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - *
- *     订单管理控制器
- * 
- */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/order") -public class OrderController extends BaseController { - - @Autowired - private OrderService orderService; - - @Autowired - private RecordService recordService; - - /** - * 查询所有订单并渲染order页面 - * - * @return 模板路径admin/admin_order - */ - @GetMapping - public String orders(@RequestParam(value = "page", defaultValue = "0") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "id") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, Model model) { - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - Page orderPage = null; - Boolean isCustomer = loginUserIsCustomer(); - if (isCustomer) { - Order orderCondition = new Order(); - orderCondition.setUserId(getLoginUserId()); - QueryCondition queryCondition = new QueryCondition(); - queryCondition.setData(orderCondition); - orderPage = orderService.findAll(page, queryCondition); - } else { - orderPage = orderService.findAll(page); - } - model.addAttribute("orders", orderPage.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - return "admin/admin_order"; - } - - - /** - * 删除订单 - * - * @param id 订单Id - * @return JsonResult - */ - @DeleteMapping(value = "/delete") - @ResponseBody - public JsonResult delete(@RequestParam("id") Long id) { - Order order = orderService.get(id); - if (order == null) { - return JsonResult.error("订单不存在"); - } - - orderService.delete(id); - - - Long postId = order.getPostId(); - Long userId = order.getUserId(); - List dateList = DateUtil.getBetweenDates(order.getStartDate(), order.getQuantity()); - - // 释放预定 - recordService.delete(postId, userId, dateList); - return JsonResult.success("删除成功"); - } - - /** - * 完结订单 - * - * @param id 订单Id - * @return JsonResult - */ - @PostMapping(value = "/finish") - @ResponseBody - public JsonResult finish(@RequestParam("id") Long id) { - Order order = orderService.get(id); - if (order == null) { - return JsonResult.error("订单不存在"); - } - - order.setStatus(OrderStatusEnum.FINISHED.getCode()); - orderService.update(order); - return JsonResult.success("完结成功"); - } - - /** - * 关闭订单 - * - * @param id 订单Id - * @return JsonResult - */ - @PostMapping(value = "/close") - @ResponseBody - @Transactional - public JsonResult close(@RequestParam("id") Long id) { - // 修改订单状态 - Order order = orderService.get(id); - if (order == null) { - return JsonResult.error("订单不存在"); - } - - order.setStatus(OrderStatusEnum.CLOSED.getCode()); - orderService.update(order); - - Long postId = order.getPostId(); - Long userId = order.getUserId(); - List dateList = DateUtil.getBetweenDates(order.getStartDate(), order.getQuantity()); - - // 释放预定 - recordService.delete(postId, userId, dateList); - return JsonResult.success("关闭成功"); - } - - /** - * 财务页面 - * - * @param model - * @return - */ - @GetMapping("/finance") - public String finance(@RequestParam(value = "startDate", required = false) String startDate, - @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "page", defaultValue = "0") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "id") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, - Model model) { - - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - Page orderPage = orderService.findAll(startDate, endDate, page); - model.addAttribute("orders", orderPage.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - - model.addAttribute("startDate", startDate); - model.addAttribute("endDate", endDate); - - Integer totalPrice = orderService.getTotalPriceSum(startDate, endDate); - model.addAttribute("totalPrice", totalPrice == null ? 0 : totalPrice); - return "admin/admin_finance"; - } - - -} diff --git a/src/main/java/com/example/hotel/controller/admin/PermissionController.java b/src/main/java/com/example/hotel/controller/admin/PermissionController.java deleted file mode 100644 index 95a8521..0000000 --- a/src/main/java/com/example/hotel/controller/admin/PermissionController.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.entity.Permission; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.enums.ResourceTypeEnum; -import com.example.hotel.service.PermissionService; -import com.example.hotel.util.PageUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * 后台权限管理控制器 - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/permission") -public class PermissionController { - - - @Autowired - private PermissionService permissionService; - - /** - * 查询所有权限并渲染permission页面 - * - * @return 模板路径admin/admin_permission - */ - @GetMapping - public String permissions(@RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "id") String sort, - @RequestParam(value = "order", defaultValue = "asc") String order, Model model) { - //权限列表 - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - - Page permissions = permissionService.findAll(page); - model.addAttribute("permissionList", permissions.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - - // 所有权限 - model.addAttribute("permissions", getPermissionList()); - return "admin/admin_permission"; - } - - /** - * 新增/修改权限 - * - * @param permission permission对象 - * @return 重定向到/admin/permission - */ - @PostMapping(value = "/save") - public String savePermission(@ModelAttribute Permission permission) { - permissionService.insertOrUpdate(permission); - return "redirect:/admin/permission"; - } - - /** - * 删除权限 - * - * @param permissionId 权限Id - * @return JsonResult - */ - @DeleteMapping(value = "/delete") - @ResponseBody - public JsonResult checkDelete(@RequestParam("id") Long permissionId) { -// // 请先删除子权限 - Integer childCount = permissionService.countChildPermission(permissionId); - if (childCount > 0) { - return JsonResult.error("请先删除子节点"); - } - permissionService.delete(permissionId); - return JsonResult.success(); - } - - /** - * 跳转到新增页面 - * - * @param model model - * @return 模板路径admin/admin_permission - */ - @GetMapping(value = "/new") - public String toAddPermission(Model model) { - // 带有等级的权限列表 - model.addAttribute("permissionList", permissionService.findPermissionListWithLevel()); - // 权限列表 - model.addAttribute("permissions", getPermissionList()); - return "admin/admin_permission_new"; - } - - /** - * 跳转到修改页面 - * - * @param permissionId permissionId - * @param model model - * @return 模板路径admin/admin_permission - */ - @GetMapping(value = "/edit") - public String toEditPermission(Model model, @RequestParam("id") Long permissionId) { - //更新的权限 - Permission permission = permissionService.get(permissionId); - model.addAttribute("updatePermission", permission); - - // 带有等级的权限列表 - model.addAttribute("permissionList", permissionService.findPermissionListWithLevel()); - // 权限列表 - model.addAttribute("permissions", getPermissionList()); - // 设置URL为编辑的URL - return "admin/admin_permission_edit"; - } - - - /** - * 所有权限 - * @return - */ - public List getPermissionList() { - //权限列表 - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.orderByAsc("sort"); - List permissions = permissionService.findAll(queryWrapper); - // 设置URL为编辑的URL - for (Permission permission : permissions) { - permission.setUrl("/admin/permission/edit?id=" + permission.getId()); - if (ResourceTypeEnum.MENU.getCode().equals(permission.getResourceType())) { - permission.setName(permission.getName() + "[" + ResourceTypeEnum.MENU.getDescription() + "]"); - } else if (ResourceTypeEnum.BUTTON.getCode().equals(permission.getResourceType())) { - permission.setName(permission.getName() + "[" + ResourceTypeEnum.BUTTON.getDescription() + "]"); - } else if (ResourceTypeEnum.PAGE.getCode().equals(permission.getResourceType())) { - permission.setName(permission.getName() + "[" + ResourceTypeEnum.PAGE.getDescription() + "]"); - } - } - return permissions; - } -} diff --git a/src/main/java/com/example/hotel/controller/admin/PostController.java b/src/main/java/com/example/hotel/controller/admin/PostController.java deleted file mode 100755 index 5b6079a..0000000 --- a/src/main/java/com/example/hotel/controller/admin/PostController.java +++ /dev/null @@ -1,263 +0,0 @@ -package com.example.hotel.controller.admin; - -import cn.hutool.http.HtmlUtil; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.dto.QueryCondition; -import com.example.hotel.exception.MyBusinessException; -import com.example.hotel.entity.*; -import com.example.hotel.enums.*; -import com.example.hotel.service.*; -import com.example.hotel.util.PageUtil; -import com.example.hotel.util.RegexUtil; -import com.example.hotel.util.SensUtils; -import com.example.hotel.vo.SearchVo; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Objects; - -/** - *
- *     后台客房管理控制器
- * 
- * - * @author : saysky - * @date : 2017/12/10 - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/post") -public class PostController extends BaseController { - - @Autowired - private PostService postService; - - @Autowired - private CategoryService categoryService; - - public static final String TITLE = "title"; - - public static final String CONTENT = "content"; - - - /** - * 处理后台获取客房列表的请求 - * - * @param model model - * @return 模板路径admin/admin_post - */ - @GetMapping - public String posts(Model model, - @RequestParam(value = "status", defaultValue = "0") Integer status, - @RequestParam(value = "keywords", defaultValue = "") String keywords, - @RequestParam(value = "searchType", defaultValue = "") String searchType, - @RequestParam(value = "postSource", defaultValue = "-1") Integer postSource, - @RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "createTime") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, - @ModelAttribute SearchVo searchVo) { - - Post condition = new Post(); - if (!StringUtils.isBlank(keywords)) { - if (TITLE.equals(searchType)) { - condition.setPostTitle(keywords); - } else { - condition.setPostContent(keywords); - } - } - condition.setPostStatus(status); - - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - Page posts = postService.findAll( - page, - new QueryCondition<>(condition, searchVo)); - - List postList = posts.getRecords(); - for(Post post : postList) { - post.setCategory(categoryService.get(post.getCateId())); - } - //封装分类和标签 - model.addAttribute("posts", postList); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - model.addAttribute("status", status); - model.addAttribute("keywords", keywords); - model.addAttribute("searchType", searchType); - model.addAttribute("postSource", postSource); - model.addAttribute("order", order); - model.addAttribute("sort", sort); - return "admin/admin_post"; - } - - - /** - * 处理跳转到新建客房页面 - * - * @return 模板路径admin/admin_editor - */ - @GetMapping(value = "/new") - public String newPost(Model model) { - //所有分类 - List allCategories = categoryService.findAll(); - model.addAttribute("categories", allCategories); - return "admin/admin_post_new"; - } - - - - /** - * 添加/更新客房 - * - * @param post Post实体 - */ - @PostMapping(value = "/save") - @ResponseBody - public JsonResult pushPost(@ModelAttribute Post post) { - // 1、提取摘要 - int postSummary = 100; - //客房摘要 - String summaryText = HtmlUtil.cleanHtmlTag(post.getPostContent()); - if (summaryText.length() > postSummary) { - String summary = summaryText.substring(0, postSummary); - post.setPostSummary(summary); - } else { - post.setPostSummary(summaryText); - } - - // 2.处理imgUrl - String postEditor = post.getPostEditor(); - if(StringUtils.isNotEmpty(postEditor)) { - List urlList = RegexUtil.getImgSrc(postEditor); - String imgUrl = SensUtils.listToStr(urlList); - post.setImgUrl(imgUrl); - } - - // 2.添加/更新入库 - postService.insertOrUpdate(post); - return JsonResult.success("发布成功"); - } - - - /** - * 处理移至回收站的请求 - * - * @param postId 客房编号 - * @return 重定向到/admin/post - */ - @PostMapping(value = "/throw") - @ResponseBody - public JsonResult moveToTrash(@RequestParam("id") Long postId) { - Post post = postService.get(postId); - if (post == null) { - throw new MyBusinessException("客房不存在"); - } - post.setPostStatus(PostStatusEnum.RECYCLE.getCode()); - postService.update(post); - return JsonResult.success("操作成功"); - - } - - /** - * 处理客房为发布的状态 - * - * @param postId 客房编号 - * @return 重定向到/admin/post - */ - @PostMapping(value = "/revert") - @ResponseBody - public JsonResult moveToPublish(@RequestParam("id") Long postId) { - Post post = postService.get(postId); - if (post == null) { - throw new MyBusinessException("客房不存在"); - } - post.setPostStatus(PostStatusEnum.PUBLISHED.getCode()); - postService.update(post); - return JsonResult.success("操作成功"); - } - - - - /** - * 处理删除客房的请求 - * - * @param postId 客房编号 - * @return 重定向到/admin/post - */ - @DeleteMapping(value = "/delete") - @ResponseBody - public JsonResult removePost(@RequestParam("id") Long postId) { - Post post = postService.get(postId); - if (post == null) { - throw new MyBusinessException("客房不存在"); - } - postService.delete(postId); - return JsonResult.success("删除成功"); - } - - /** - * 批量删除 - * - * @param ids 客房ID列表 - * @return 重定向到/admin/post - */ - @DeleteMapping(value = "/batchDelete") - @ResponseBody - public JsonResult batchDelete(@RequestParam("ids") List ids) { - //批量操作 - //1、防止恶意操作 - if (ids == null || ids.size() == 0 || ids.size() >= 100) { - return new JsonResult(ResultCodeEnum.FAIL.getCode(), "参数不合法!"); - } - //2、检查用户权限 - //客房作者才可以删除 - List postList = postService.findByBatchIds(ids); - //3、如果当前状态为回收站,则删除;否则,移到回收站 - for (Post post : postList) { - if (Objects.equals(post.getPostStatus(), PostStatusEnum.RECYCLE.getCode())) { - postService.delete(post.getId()); - } else { - post.setPostStatus(PostStatusEnum.RECYCLE.getCode()); - postService.update(post); - } - } - return JsonResult.success("删除成功"); - } - - - /** - * 跳转到编辑客房页面 - * - * @param postId 客房编号 - * @param model model - * @return 模板路径admin/admin_editor - */ - @GetMapping(value = "/edit") - public String editPost(@RequestParam("id") Long postId, Model model) { - Post post = postService.get(postId); - if (post == null) { - throw new MyBusinessException("客房不存在"); - } - - //当前客房分类 - Category category = categoryService.get(post.getCateId()); - post.setCategory(category); - model.addAttribute("post", post); - - - //所有分类 - List allCategories = categoryService.findAll(); - model.addAttribute("categories", allCategories); - return "admin/admin_post_edit"; - } - - - - -} diff --git a/src/main/java/com/example/hotel/controller/admin/ProfileController.java b/src/main/java/com/example/hotel/controller/admin/ProfileController.java deleted file mode 100644 index 3b6e3c4..0000000 --- a/src/main/java/com/example/hotel/controller/admin/ProfileController.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.example.hotel.common.constant.CommonConstant; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.entity.User; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.service.UserService; -import com.example.hotel.util.Md5Util; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.Objects; - -/** - * 后台用户管理控制器 - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/user") -public class ProfileController extends BaseController { - - @Autowired - private UserService userService; - - /** - * 获取用户信息并跳转 - * - * @return 模板路径admin/admin_profile - */ - @GetMapping("/profile") - public String profile(Model model) { - //1.用户信息 - User user = getLoginUser(); - model.addAttribute("user", user); - return "admin/admin_profile"; - } - - - /** - * 处理修改用户资料的请求 - * - * @param user user - * @return JsonResult - */ - @PostMapping(value = "/profile/save") - @ResponseBody - public JsonResult saveProfile(@ModelAttribute User user) { - User loginUser = getLoginUser(); - - User saveUser = userService.get(loginUser.getId()); - saveUser.setUserPass(null); - saveUser.setId(loginUser.getId()); - saveUser.setUserName(user.getUserName()); - saveUser.setUserDisplayName(user.getUserDisplayName()); - saveUser.setUserAvatar(user.getUserAvatar()); - saveUser.setUserDesc(user.getUserDesc()); - saveUser.setIdCard(user.getIdCard()); - userService.insertOrUpdate(saveUser); - return JsonResult.success("资料修改成功,请重新登录"); - } - - - /** - * 处理修改密码的请求 - * - * @param beforePass 旧密码 - * @param newPass 新密码 - * @return JsonResult - */ - @PostMapping(value = "/changePass") - @ResponseBody - public JsonResult changePass(@ModelAttribute("beforePass") String beforePass, - @ModelAttribute("newPass") String newPass) { - - // 1.密码长度是否合法 - if (newPass.length() > 20 || newPass.length() < 6) { - return JsonResult.error("用户密码长度为6-20位!"); - } - - // 2.比较密码 - User loginUser = getLoginUser(); - User user = userService.get(loginUser.getId()); - if (user != null && Objects.equals(user.getUserPass(), Md5Util.toMd5(beforePass, CommonConstant.PASSWORD_SALT, 10))) { - userService.updatePassword(user.getId(), newPass); - } else { - return JsonResult.error("旧密码错误"); - } - return JsonResult.success("密码重置成功"); - } - - -} diff --git a/src/main/java/com/example/hotel/controller/admin/RoleController.java b/src/main/java/com/example/hotel/controller/admin/RoleController.java deleted file mode 100644 index 74a9476..0000000 --- a/src/main/java/com/example/hotel/controller/admin/RoleController.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.entity.Permission; -import com.example.hotel.entity.Role; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.enums.ResourceTypeEnum; -import com.example.hotel.service.PermissionService; -import com.example.hotel.service.RoleService; -import com.example.hotel.util.PageUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.logging.log4j.util.Strings; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -/** - * 后台角色管理控制器 - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/role") -public class RoleController { - - @Autowired - private RoleService roleService; - - @Autowired - private PermissionService permissionService; - - /** - * 查询所有角色并渲染role页面 - * - * @return 模板路径admin/admin_role - */ - @GetMapping - public String roles(@RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "level") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, Model model) { - //角色列表 - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - - Page roles = roleService.findAll(page); - model.addAttribute("roles", roles.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - - return "admin/admin_role"; - } - - /** - * 新增/修改角色 - * - * @param role role对象 - * @return 重定向到/admin/role - */ - @PostMapping(value = "/save") - @ResponseBody - public JsonResult saveRole(@ModelAttribute Role role, - @RequestParam(value = "permissionIds") String permissionIds) { - - if (Strings.isNotEmpty(permissionIds)) { - String[] arr = permissionIds.split(","); - List permissions = new ArrayList<>(); - for (String permissionId : arr) { - Permission permission = new Permission(); - permission.setId(Long.valueOf(permissionId)); - permissions.add(permission); - } - role.setPermissions(permissions); - } - roleService.insertOrUpdate(role); - return JsonResult.success(); - } - - /** - * 删除角色 - * - * @param roleId 角色Id - * @return JsonResult - */ - @DeleteMapping(value = "/delete") - @ResponseBody - public JsonResult checkDelete(@RequestParam("id") Long roleId) { - //判断这个角色有没有用户 - Integer userCount = roleService.countUserByRoleId(roleId); - if (userCount != 0) { - return JsonResult.error("当前角色已关联用户,无法删除"); - } - roleService.delete(roleId); - return JsonResult.success("删除角色成功"); - } - - - /** - * 添加用户页面 - * - * @return 模板路径admin/admin_edit - */ - @GetMapping("/new") - public String addRole(Model model) { - // 所有权限 - model.addAttribute("permissions", getPermissionList()); - return "admin/admin_role_add"; - } - - /** - * 跳转到修改页面 - * - * @param roleId roleId - * @param model model - * @return 模板路径admin/admin_role - */ - @GetMapping(value = "/edit") - public String toEditRole(Model model, @RequestParam("id") Long roleId) { - //更新的角色 - Role role = roleService.findByRoleId(roleId); - //当前角色的权限列表 - role.setPermissions(permissionService.listPermissionsByRoleId(roleId)); - model.addAttribute("updateRole", role); - - // 所有权限 - model.addAttribute("permissions", getPermissionList()); - - // 当前角色的权限列表 - List currentPermissionIds = permissionService.findPermissionByRoleId(roleId).stream().map(p -> p.getId()).collect(Collectors.toList()); - model.addAttribute("currentPermissionIds", currentPermissionIds); - return "admin/admin_role_edit"; - } - - /** - * 所有权限 - * @return - */ - public List getPermissionList() { - //权限列表 - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.orderByAsc("sort"); - List permissions = permissionService.findAll(queryWrapper); - // 设置URL为编辑的URL - for (Permission permission : permissions) { - permission.setUrl("/admin/permission/edit?id=" + permission.getId()); - if (ResourceTypeEnum.MENU.getCode().equals(permission.getResourceType())) { - permission.setName(permission.getName() + "[" + ResourceTypeEnum.MENU.getDescription() + "]"); - } else if (ResourceTypeEnum.BUTTON.getCode().equals(permission.getResourceType())) { - permission.setName(permission.getName() + "[" + ResourceTypeEnum.BUTTON.getDescription() + "]"); - } else if (ResourceTypeEnum.PAGE.getCode().equals(permission.getResourceType())) { - permission.setName(permission.getName() + "[" + ResourceTypeEnum.PAGE.getDescription() + "]"); - } - } - return permissions; - } -} diff --git a/src/main/java/com/example/hotel/controller/admin/UserController.java b/src/main/java/com/example/hotel/controller/admin/UserController.java deleted file mode 100644 index 3e1fb41..0000000 --- a/src/main/java/com/example/hotel/controller/admin/UserController.java +++ /dev/null @@ -1,228 +0,0 @@ -package com.example.hotel.controller.admin; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.entity.*; -import com.example.hotel.enums.RoleEnum; -import com.example.hotel.service.*; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.util.PageUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * 后台用户管理控制器 - */ -@Slf4j -@Controller -@RequestMapping(value = "/admin/user") -public class UserController extends BaseController { - - @Autowired - private UserService userService; - - @Autowired - private RoleService roleService; - - - @Autowired - private UserRoleRefService userRoleRefService; - - - public static final String USER_NAME = "userName"; - public static final String USER_DISPLAY_NAME = "userDisplayName"; - public static final String EMAIL = "email"; - - /** - * 查询所有分类并渲染user页面 - * - * @return 模板路径admin/admin_user - */ - @GetMapping("/customer") - public String customers( - @RequestParam(value = "status", defaultValue = "0") Integer status, - @RequestParam(value = "keywords", defaultValue = "") String keywords, - @RequestParam(value = "searchType", defaultValue = "") String searchType, - @RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "createTime") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, Model model) { - //用户列表 - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - User condition = new User(); - condition.setStatus(status); - if (!StringUtils.isBlank(keywords)) { - if (USER_NAME.equals(searchType)) { - condition.setUserName(keywords); - } else if (USER_DISPLAY_NAME.equals(searchType)) { - condition.setUserDisplayName(keywords); - } else if (EMAIL.equals(searchType)) { - condition.setIdCard(keywords); - } - } - String role = RoleEnum.CUSTOMER.getValue(); - Page users = userService.findByRoleAndCondition(role, condition, page); - - //角色列表 - Integer maxLevel = roleService.findMaxLevelByUserId(getLoginUserId()); - List roles = roleService.findByLessThanLevel(maxLevel); - model.addAttribute("roles", roles); - model.addAttribute("users", users.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - model.addAttribute("status", status); - model.addAttribute("keywords", keywords); - model.addAttribute("searchType", searchType); - model.addAttribute("sort", sort); - model.addAttribute("order", order); - model.addAttribute("currentRole", role); - return "admin/admin_user"; - } - - /** - * 查询所有分类并渲染user页面 - * - * @return 模板路径admin/admin_user - */ - @GetMapping("/worker") - public String works( - @RequestParam(value = "status", defaultValue = "0") Integer status, - @RequestParam(value = "keywords", defaultValue = "") String keywords, - @RequestParam(value = "searchType", defaultValue = "") String searchType, - @RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "createTime") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, Model model) { - //用户列表 - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - User condition = new User(); - condition.setStatus(status); - if (!StringUtils.isBlank(keywords)) { - if (USER_NAME.equals(searchType)) { - condition.setUserName(keywords); - } else if (USER_DISPLAY_NAME.equals(searchType)) { - condition.setUserDisplayName(keywords); - } else if (EMAIL.equals(searchType)) { - condition.setIdCard(keywords); - } - } - String role = RoleEnum.WORKER.getValue(); - Page users = userService.findByRoleAndCondition(role, condition, page); - - //角色列表 - Integer maxLevel = roleService.findMaxLevelByUserId(getLoginUserId()); - List roles = roleService.findByLessThanLevel(maxLevel); - model.addAttribute("roles", roles); - model.addAttribute("users", users.getRecords()); - model.addAttribute("pageInfo", PageUtil.convertPageVo(page)); - model.addAttribute("status", status); - model.addAttribute("keywords", keywords); - model.addAttribute("searchType", searchType); - model.addAttribute("sort", sort); - model.addAttribute("order", order); - model.addAttribute("currentRole", role); - return "admin/admin_user"; - } - - - /** - * 删除用户 - * - * @param userId 用户Id - * @return JsonResult - */ - @DeleteMapping(value = "/delete") - @ResponseBody - public JsonResult removeUser(@RequestParam("id") Long userId) { - userService.delete(userId); - return JsonResult.success("删除成功"); - } - - /** - * 添加用户页面 - * - * @return 模板路径admin/admin_edit - */ - @GetMapping("/new") - public String addUser(Model model) { - - //角色列表 - List roles = roleService.findAll(); - model.addAttribute("roles", roles); - - return "admin/admin_user_add"; - } - - /** - * 编辑用户页面 - * - * @return 模板路径admin/admin_edit - */ - @GetMapping("/edit") - public String edit(@RequestParam("id") Long userId, Model model) { - User user = userService.get(userId); - if (user != null) { - model.addAttribute("user", user); - //该用户的角色 - Role currentRole = roleService.findByUserId(userId); - model.addAttribute("currentRole", currentRole); - - //角色列表 - List roles = roleService.findAll(); - model.addAttribute("roles", roles); - - - return "admin/admin_user_edit"; - } - return this.renderNotFound(); - } - - /** - * 批量删除 - * - * @param ids 用户ID列表 - * @return - */ - @DeleteMapping(value = "/batchDelete") - @ResponseBody - public JsonResult batchDelete(@RequestParam("ids") List ids) { - //批量操作 - if (ids == null || ids.size() == 0 || ids.size() >= 100) { - return JsonResult.error("参数不合法!"); - } - List userList = userService.findByBatchIds(ids); - for (User user : userList) { - userService.delete(user.getId()); - } - return JsonResult.success("删除成功"); - } - - /** - * 新增/修改用户 - * - * @param user user - * @return 重定向到/admin/user - */ - @PostMapping(value = "/save") - @ResponseBody - @Transactional(rollbackFor = Exception.class) - public JsonResult saveUser(@ModelAttribute User user, - @RequestParam(value = "roleId", required = false) Long roleId) { - // 1.添加用户 - userService.insertOrUpdate(user); - if(roleId != null) { - // 2.先删除该用户的角色关联 - userRoleRefService.deleteByUserId(user.getId()); - // 3.添加角色关联 - userRoleRefService.insert(new UserRoleRef(user.getId(), roleId)); - } - return JsonResult.success("保存成功"); - } - -} diff --git a/src/main/java/com/example/hotel/controller/common/BaseController.java b/src/main/java/com/example/hotel/controller/common/BaseController.java deleted file mode 100755 index db94f26..0000000 --- a/src/main/java/com/example/hotel/controller/common/BaseController.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.example.hotel.controller.common; - -import com.example.hotel.entity.User; -import com.example.hotel.enums.RoleEnum; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.subject.Subject; - -/** - * Controller抽象类 - */ -public abstract class BaseController { - - /** - * 渲染404页面 - * - * @return redirect:/404 - */ - public String renderNotFound() { - return "forward:/404"; - } - - - /** - * 渲染404页面 - * - * @return redirect:/404 - */ - public String renderNotAllowAccess() { - return "redirect:/403"; - } - - /** - * 当前登录用户 - * - * @return - */ - public User getLoginUser() { - Subject subject = SecurityUtils.getSubject(); - if (subject.isAuthenticated()) { - return (User) subject.getPrincipal(); - } - return null; - } - - /** - * 当前用户ID - * - * @return - */ - public Long getLoginUserId() { - return getLoginUser().getId(); - } - - /** - * 当前用户是管理员 - * - * @return - */ - public Boolean loginUserIsAdmin() { - User loginUser = getLoginUser(); - if (loginUser != null) { - return RoleEnum.ADMIN.getValue().equalsIgnoreCase(loginUser.getRole()); - } - return false; - } - - /** - * 当前用户是工作人员 - * - * @return - */ - public Boolean loginUserIsWorker() { - User loginUser = getLoginUser(); - if (loginUser != null) { - return RoleEnum.WORKER.getValue().equalsIgnoreCase(loginUser.getRole()); - } - return false; - } - - - /** - * 当前用户是消费者 - * - * @return - */ - public Boolean loginUserIsCustomer() { - User loginUser = getLoginUser(); - if (loginUser != null) { - return RoleEnum.CUSTOMER.getValue().equalsIgnoreCase(loginUser.getRole()); - } - return false; - } - - -} diff --git a/src/main/java/com/example/hotel/controller/common/CommonController.java b/src/main/java/com/example/hotel/controller/common/CommonController.java deleted file mode 100755 index dc1cf45..0000000 --- a/src/main/java/com/example/hotel/controller/common/CommonController.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.example.hotel.controller.common; - -import com.example.hotel.enums.CommonParamsEnum; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.web.servlet.error.ErrorController; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; - -import javax.servlet.http.HttpServletRequest; - -/** - * 错误页面控制器 - */ -@Slf4j -@Controller -public class CommonController implements ErrorController { - - - /** - * 渲染404,500 - * - * @param request request - * @return String - */ - @GetMapping(value = "/error") - public String handleError(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); - if (statusCode.equals(CommonParamsEnum.NOT_FOUND.getValue())) { - return "redirect:/404"; - } else { - return "redirect:/500"; - } - } - - /** - * 渲染403页面 - * - * @return String - */ - @GetMapping(value = "/403") - public String fourZeroThree() { - return "common/error/403"; - } - - - /** - * 渲染404页面 - * - * @return String - */ - @GetMapping(value = "/404") - public String fourZeroFour() { - return "common/error/404"; - } - - - /** - * 渲染500页面 - * - * @return String - */ - @GetMapping(value = "/500") - public String fiveZeroZero() { - return "common/error/500"; - } - - /** - * Returns the path of the error page. - * - * @return the error path - */ - @Override - public String getErrorPath() { - return "/error"; - } -} diff --git a/src/main/java/com/example/hotel/controller/home/FrontCategoryController.java b/src/main/java/com/example/hotel/controller/home/FrontCategoryController.java deleted file mode 100644 index 581512d..0000000 --- a/src/main/java/com/example/hotel/controller/home/FrontCategoryController.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.example.hotel.controller.home; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.PostQueryCondition; -import com.example.hotel.entity.Category; -import com.example.hotel.entity.Post; -import com.example.hotel.service.CategoryService; -import com.example.hotel.service.PostService; -import com.example.hotel.util.PageUtil; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.List; - -/** - * @author 言曌 - * @date 2020/3/11 4:59 下午 - */ -@Controller -public class FrontCategoryController extends BaseController { - - @Autowired - private PostService postService; - - @Autowired - private CategoryService categoryService; - - /** - * 分类列表 - * - * @param model - * @return - */ - @GetMapping("/category") - public String category(@RequestParam(value = "keywords", required = false) String keywords, - Model model) { - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.orderByDesc("cate_sort"); - if (StringUtils.isNotEmpty(keywords)) { - queryWrapper.like("cate_name", keywords); - } - List categories = categoryService.findAll(queryWrapper); - model.addAttribute("categories", categories); - return "home/category"; - } - - - /** - * 分类对应的帖子列表 - * - * @param model - * @return - */ - @GetMapping("/category/{id}") - public String index(@PathVariable("id") Long cateId, - @RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "10") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "createTime") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, - Model model) { - - Category category = categoryService.get(cateId); - if(category == null) { - return renderNotFound(); - } - - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - PostQueryCondition condition = new PostQueryCondition(); - condition.setCateId(cateId); - Page postPage = postService.findPostByCondition(condition, page); - model.addAttribute("posts", postPage); - model.addAttribute("category", category); - return "home/category_post"; - } - - -} diff --git a/src/main/java/com/example/hotel/controller/home/FrontPostController.java b/src/main/java/com/example/hotel/controller/home/FrontPostController.java deleted file mode 100644 index 107bb9a..0000000 --- a/src/main/java/com/example/hotel/controller/home/FrontPostController.java +++ /dev/null @@ -1,342 +0,0 @@ -package com.example.hotel.controller.home; - -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.entity.*; -import com.example.hotel.enums.OrderStatusEnum; -import com.example.hotel.service.*; -import com.example.hotel.util.DateUtil; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Objects; - -/** - * @author 言曌 - * @date 2020/3/11 4:59 下午 - */ -@Controller -public class FrontPostController extends BaseController { - - @Autowired - private CategoryService categoryService; - - @Autowired - private PostService postService; - - @Autowired - private OrderService orderService; - - @Autowired - private RecordService recordService; - - @Autowired - private UserService userService; - - /** - * 帖子详情 - * - * @param id - * @param model - * @return - */ - @GetMapping("/post/{id}") - public String postDetails(@PathVariable("id") Long id, - @RequestParam(value = "startDate", required = false) String start, - @RequestParam(value = "quantity", defaultValue = "1") Integer quantity, - Model model) { - DateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT); - - if (quantity == null || quantity < 1) { - quantity = 1; - } - - Date today = new Date(); - - // 判断入住日期是否合法 - if (StringUtils.isEmpty(start)) { - start = dateFormat.format(today); - } else { - try { - Date startDate = dateFormat.parse(start); - if (startDate.before(today)) { - start = dateFormat.format(today); - } - } catch (ParseException e) { - start = dateFormat.format(today); - e.printStackTrace(); - } - } - - // 客房 - Post post = postService.get(id); - if (post == null) { - return renderNotFound(); - } - // 分类 - Category category = categoryService.get(post.getCateId()); - post.setCategory(category); - model.addAttribute("post", post); - - String[] imgUrlList = post.getImgUrl().split(","); - model.addAttribute("imgUrlList", imgUrlList); - - - // 该房间的预定记录 - List recordList = recordService.findByPostId(id); - model.addAttribute("recordList", recordList); - - // 分类列表 - List categoryList = categoryService.findAll(); - model.addAttribute("categoryList", categoryList); - - model.addAttribute("startDate", start); - model.addAttribute("quantity", quantity); - return "home/post"; - } - - - /** - * 结算页面 - * - * @param postId - * @param start - * @param quantity - * @param model - * @return - */ - @GetMapping("/checkout") - public String checkout(@RequestParam("postId") Long postId, - @RequestParam(value = "startDate", required = false) String start, - @RequestParam(value = "quantity", defaultValue = "1") Integer quantity, - Model model) { - DateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT); - - if (quantity == null || quantity < 1) { - quantity = 1; - } - - Date today = new Date(); - - // 判断入住日期是否合法 - if (StringUtils.isEmpty(start)) { - start = dateFormat.format(today); - } else { - try { - Date startDate = dateFormat.parse(start); - if (startDate.before(today)) { - start = dateFormat.format(today); - } - } catch (ParseException e) { - start = dateFormat.format(today); - e.printStackTrace(); - } - } - - Post post = postService.get(postId); - if (post == null) { - return this.renderNotFound(); - } - - User user = getLoginUser(); - if (user == null) { - return "redirect:/"; - } - - // 分类列表 - List categoryList = categoryService.findAll(); - model.addAttribute("categoryList", categoryList); - - model.addAttribute("post", post); - model.addAttribute("startDate", start); - model.addAttribute("quantity", quantity); - model.addAttribute("user", user); - return "home/checkout"; - } - - /** - * 创建订单 - * - * @param postId - * @param start - * @param quantity - * @return - */ - @GetMapping("/checkOrder") - @ResponseBody - public JsonResult checkOrder(@RequestParam(value = "postId") Long postId, - @RequestParam(value = "startDate") String start, - @RequestParam(value = "quantity") Integer quantity) { - User user = getLoginUser(); - if (user == null) { - return JsonResult.error("请先登录"); - } - - Post post = postService.get(postId); - if (post == null) { - return JsonResult.error("客房不存在"); - } - - DateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT); - - if (quantity == null || quantity < 1 || quantity > 7) { - return JsonResult.error("天数不合法"); - } - - Date today = new Date(); - - // 判断入住日期是否合法 - if (StringUtils.isEmpty(start)) { - start = dateFormat.format(today); - } else { - try { - Date startDate = dateFormat.parse(start); - if (startDate.before(today) && !Objects.equals(start, dateFormat.format(today))) { - return JsonResult.error("不能预定过去的日期"); - } - } catch (ParseException e) { - e.printStackTrace(); - return JsonResult.error("预定日期格式不合法"); - } - } - - // 查询日期列表 - List dateList = DateUtil.getBetweenDates(start, quantity); - // 判断客房是否可以预定 - List recordList = recordService.findByPostIdAndRecordDate(postId, dateList); - if (recordList.size() > 0) { - return JsonResult.error("房间已被人预定,请重新选择房间和日期"); - } - return JsonResult.success("可以预定"); - } - - /** - * 创建订单 - * - * @param postId - * @param start - * @param quantity - * @param userName - * @param userDisplayName - * @param idCard - * @return - */ - @PostMapping("/order") - @Transactional - @ResponseBody - public JsonResult addOrder(@RequestParam(value = "postId") Long postId, - @RequestParam(value = "startDate") String start, - @RequestParam(value = "quantity") Integer quantity, - @RequestParam(value = "userName") String userName, - @RequestParam(value = "userDisplayName") String userDisplayName, - @RequestParam(value = "idCard") String idCard) { - User user = getLoginUser(); - if (user == null) { - return JsonResult.error("请先登录"); - } - - Post post = postService.get(postId); - if (post == null) { - return JsonResult.error("客房不存在"); - } - - DateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT); - - if (quantity == null || quantity < 1 || quantity > 7) { - return JsonResult.error("天数不合法"); - } - - Date today = new Date(); - - // 判断入住日期是否合法 - if (StringUtils.isEmpty(start)) { - start = dateFormat.format(today); - } else { - try { - Date startDate = dateFormat.parse(start); - if (startDate.before(today) && !Objects.equals(start, dateFormat.format(today))) { - return JsonResult.error("不能预定过去的日期"); - } - } catch (ParseException e) { - e.printStackTrace(); - return JsonResult.error("预定日期格式不合法"); - } - } - - // 查询日期列表 - List dateList = DateUtil.getBetweenDates(start, quantity); - // 判断客房是否可以预定 - List recordList = recordService.findByPostIdAndRecordDate(postId, dateList); - if (recordList.size() > 0) { - return JsonResult.error("房间已被人预定,请重新选择房间和日期"); - } - - // 支付省略 - // 添加订单 - Order order = new Order(); - order.setPostId(postId); - order.setQuantity(quantity); - order.setStartDate(start); - order.setName(userDisplayName); - order.setPhone(userName); - order.setIdCard(idCard); - order.setUserId(user.getId()); - order.setStatus(OrderStatusEnum.HAS_PAY.getCode()); - order.setPostTitle(post.getPostTitle()); - order.setPostNumber(post.getNumber()); - order.setPrice(post.getPrice()); - order.setTotalPrice(post.getPrice() * quantity); - order.setCreateTime(new Date()); - order.setUpdateTime(new Date()); - orderService.insert(order); - - // 添加预定记录 - for (String recordDate : dateList) { - Record record = new Record(); - record.setPostId(postId); - record.setUserId(user.getId()); - record.setRecordDate(recordDate); - recordService.insert(record); - } - return JsonResult.success("预定成功", order.getId()); - } - - @GetMapping("/order/{id}") - public String order(@PathVariable("id") Long id, Model model) { - Order order = orderService.get(id); - if (order == null) { - return this.renderNotFound(); - } - - User user = getLoginUser(); - if (user == null) { - return "redirect:/"; - } - - Boolean isCustomer = loginUserIsCustomer(); - if (!Objects.equals(order.getUserId(), user.getId()) && isCustomer) { - return this.renderNotAllowAccess(); - } - model.addAttribute("order", order); - - - // 分类列表 - List categoryList = categoryService.findAll(); - model.addAttribute("categoryList", categoryList); - - model.addAttribute("user", userService.get(order.getUserId())); - return "home/order"; - } - - - -} diff --git a/src/main/java/com/example/hotel/controller/home/IndexController.java b/src/main/java/com/example/hotel/controller/home/IndexController.java deleted file mode 100644 index 66bd1fc..0000000 --- a/src/main/java/com/example/hotel/controller/home/IndexController.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.example.hotel.controller.home; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.dto.PostQueryCondition; -import com.example.hotel.entity.*; -import com.example.hotel.exception.MyBusinessException; -import com.example.hotel.service.*; -import com.example.hotel.util.DateUtil; -import com.example.hotel.util.PageUtil; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -/** - * @author 言曌 - * @date 2020/3/9 11:00 上午 - */ - -@Controller -public class IndexController extends BaseController { - - @Autowired - private PostService postService; - - @Autowired - private CategoryService categoryService; - - - @GetMapping("/") - public String index(@RequestParam(value = "page", defaultValue = "1") Integer pageNumber, - @RequestParam(value = "size", defaultValue = "9") Integer pageSize, - @RequestParam(value = "sort", defaultValue = "createTime") String sort, - @RequestParam(value = "order", defaultValue = "desc") String order, - @RequestParam(value = "startDate", required = false) String start, - @RequestParam(value = "quantity", defaultValue = "1") Integer quantity, - @RequestParam(value = "cateId", defaultValue = "0") Long cateId, - Model model) { - DateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT); - - if (quantity == null || quantity < 1) { - quantity = 1; - } - - Date today = new Date(); - - // 判断入住日期是否合法 - if (StringUtils.isEmpty(start)) { - start = dateFormat.format(today); - } else { - try { - Date startDate = dateFormat.parse(start); - if (startDate.before(today)) { - start = dateFormat.format(today); - } - } catch (ParseException e) { - start = dateFormat.format(today); - e.printStackTrace(); - } - } - - - PostQueryCondition condition = new PostQueryCondition(); - // 查询日期列表 - List dateList = DateUtil.getBetweenDates(start, quantity); - condition.setDateList(dateList); - condition.setCateId(cateId); - Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order); - Page postPage = postService.findPostByCondition(condition, page); - model.addAttribute("posts", postPage); - - // 分类列表 - List categoryList = categoryService.findAll(); - model.addAttribute("categoryList", categoryList); - model.addAttribute("quantity", quantity); - model.addAttribute("startDate", start); - model.addAttribute("cateId", cateId); - return "home/index"; - } - - -} diff --git a/src/main/java/com/example/hotel/controller/home/LoginController.java b/src/main/java/com/example/hotel/controller/home/LoginController.java deleted file mode 100644 index 038dd58..0000000 --- a/src/main/java/com/example/hotel/controller/home/LoginController.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.example.hotel.controller.home; - -import cn.hutool.core.lang.Validator; -import com.example.hotel.common.constant.CommonConstant; -import com.example.hotel.controller.common.BaseController; -import com.example.hotel.entity.Role; -import com.example.hotel.entity.User; -import com.example.hotel.entity.UserRoleRef; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.enums.CommonParamsEnum; -import com.example.hotel.enums.TrueFalseEnum; -import com.example.hotel.enums.UserStatusEnum; -import com.example.hotel.service.*; -import com.example.hotel.util.Md5Util; -import com.example.hotel.util.RegexUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.RandomUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.IncorrectCredentialsException; -import org.apache.shiro.authc.LockedAccountException; -import org.apache.shiro.authc.UnknownAccountException; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.subject.Subject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.*; - -import javax.mail.MessagingException; -import java.util.Set; - -@Controller -@Slf4j -public class LoginController extends BaseController { - - @Autowired - private PermissionService permissionService; - - @Autowired - private UserService userService; - - @Autowired - private RoleService roleService; - - @Autowired - private UserRoleRefService userRoleRefService; - - /** - * 验证登录信息 - * - * @param userName 登录名:身份证号码/手机号 - * @param userPass password 密码 - * @return JsonResult JsonResult - */ - @PostMapping(value = "/login") - @ResponseBody - public JsonResult getLogin(@RequestParam("userName") String userName, - @RequestParam("userPass") String userPass) { - Subject subject = SecurityUtils.getSubject(); - UsernamePasswordToken token = new UsernamePasswordToken(userName, userPass); - try { - subject.login(token); - if (subject.isAuthenticated()) { - //登录成功,修改登录错误次数为0 - User user = (User) subject.getPrincipal(); - Set permissionUrls = permissionService.findPermissionUrlsByUserId(user.getId()); - subject.getSession().setAttribute("permissionUrls", permissionUrls); - return JsonResult.success("登录成功"); - } - } catch (UnknownAccountException e) { - return JsonResult.error("账号不存在"); - } catch (IncorrectCredentialsException e) { - e.printStackTrace(); - return JsonResult.error("账号或密码错误"); - } catch (LockedAccountException e) { - return JsonResult.error(e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - log.info(e.getMessage()); - } - return JsonResult.error("服务器内部错误"); - } - - - /** - * 退出登录 - * - * @return 重定向到/login - */ - @GetMapping(value = "/logout") - public String logOut() { - Subject subject = SecurityUtils.getSubject(); - subject.logout(); - return "redirect:/"; - } - - /** - * 退出登录 - * - * @return 重定向到/login - */ - @PostMapping(value = "/logout") - @ResponseBody - public JsonResult ajaxLogOut() { - Subject subject = SecurityUtils.getSubject(); - subject.logout(); - return JsonResult.success(); - } - - /** - * 验证注册信息 - * - * @param userName 手机号 - * @param idCard 身份证号码 - * @return JsonResult JsonResult - */ - @PostMapping(value = "/register") - @ResponseBody - @Transactional - public JsonResult getRegister(@RequestParam("userName") String userName, - @RequestParam("userPass") String userPass, - @RequestParam("idCard") String idCard, - @RequestParam("userDisplayName") String userDisplayName) { - // 1.校验是否输入完整 - if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(userPass) || StringUtils.isEmpty(idCard)) { - return JsonResult.error("请填写完整信息"); - } - - // 2.密码长度是否合法 - if (userPass.length() > 20 || userPass.length() < 6) { - return JsonResult.error("用户密码长度为6-20位!"); - } - - //3.创建用户 - User user = new User(); - user.setUserName(userName); - user.setUserDisplayName(userDisplayName); - user.setIdCard(idCard); - user.setUserPass(Md5Util.toMd5(userPass, CommonConstant.PASSWORD_SALT, 10)); - user.setUserAvatar("/static/images/avatar/" + RandomUtils.nextInt(1, 41) + ".jpeg"); - user.setStatus(UserStatusEnum.NORMAL.getCode()); - userService.insert(user); - - //4.关联角色 - Role defaultRole = roleService.findDefaultRole(); - if (defaultRole != null) { - userRoleRefService.insert(new UserRoleRef(user.getId(), defaultRole.getId())); - } - return JsonResult.success("注册成功"); - } - - /** - * 处理忘记密码 - * - * @param userName 手机号 - * @param idCard 身份证号码 - * @return JsonResult - */ - @PostMapping(value = "/forget") - @ResponseBody - public JsonResult getForget(@RequestParam("userName") String userName, - @RequestParam("userPass") String userPass, - @RequestParam("idCard") String idCard) { - - User user = userService.findByUserName(userName); - if (user != null && idCard.equalsIgnoreCase(user.getIdCard())) { - //1.修改密码 - userService.updatePassword(user.getId(), userPass); - return JsonResult.success("密码重置成功,新密码为" + userPass); - } else { - return JsonResult.error("手机号和电子身份证号码不一致"); - } - } - - /** - * 检查用户是否登录 - * - * @return JsonResult - */ - @GetMapping(value = "/checkLogin") - @ResponseBody - public JsonResult checkLogin() { - User user = getLoginUser(); - if (user == null) { - return JsonResult.error("请先登录"); - } else { - return JsonResult.success(); - } - } - - -} diff --git a/src/main/java/com/example/hotel/service/CategoryService.java b/src/main/java/com/example/hotel/service/CategoryService.java deleted file mode 100755 index 710d394..0000000 --- a/src/main/java/com/example/hotel/service/CategoryService.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.example.hotel.service; - - -import com.example.hotel.common.base.BaseService; -import com.example.hotel.entity.Category; - -import java.util.List; - -/** - *
- *     分类业务逻辑接口
- * 
- * - * @author : saysky - * @date : 2017/11/30 - */ -public interface CategoryService extends BaseService { - - /** - * 查询所有分类目录,带count和根据level封装name - * - * @return 返回List集合 - */ - List findByUserId(Long userId); - - /** - * 获得某个分类的所有客房数 - * - * @param cateId 分类Id - * @return 客房数 - */ - Integer countPostByCateId(Long cateId); - - /** - * 根据用户ID删除 - * - * @param userId - * @return - */ - Integer deleteByUserId(Long userId); - - /** - * 将分类ID列表转成分类 - * - * @param cateIds - * @param userId - * @return - */ - List cateIdsToCateList(List cateIds, Long userId); -} diff --git a/src/main/java/com/example/hotel/service/MailService.java b/src/main/java/com/example/hotel/service/MailService.java deleted file mode 100755 index 145475e..0000000 --- a/src/main/java/com/example/hotel/service/MailService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.hotel.service; - - -import javax.mail.MessagingException; - -/** - *
- *     邮件发送业务逻辑接口
- * 
- */ -public interface MailService { - - /** - * 发送邮件 - * - * @param to 接收者 - * @param title 标题 - * @param content 内容 - */ - void sendMail(String to, String title, String content) throws MessagingException; - -} diff --git a/src/main/java/com/example/hotel/service/OrderService.java b/src/main/java/com/example/hotel/service/OrderService.java deleted file mode 100644 index 9f8320a..0000000 --- a/src/main/java/com/example/hotel/service/OrderService.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.example.hotel.service; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.common.base.BaseService; -import com.example.hotel.entity.Order; -import com.example.hotel.entity.User; - -import java.util.List; - -/** - * 订单 - * - * @author 言曌 - * @date 2020/4/6 2:00 下午 - */ -public interface OrderService extends BaseService { - - /** - * 根据时间范围查询总金额 - * - * @param startDate - * @param endDate - * @return - */ - Integer getTotalPriceSum(String startDate, String endDate); - - /** - * 根据时间范围查询 - * @param startDate - * @param endDate - * @param page - * @return - */ - Page findAll(String startDate, String endDate, Page page); -} diff --git a/src/main/java/com/example/hotel/service/PermissionService.java b/src/main/java/com/example/hotel/service/PermissionService.java deleted file mode 100644 index 134e92d..0000000 --- a/src/main/java/com/example/hotel/service/PermissionService.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.example.hotel.service; - -import com.example.hotel.entity.Permission; -import com.example.hotel.common.base.BaseService; - -import java.util.List; -import java.util.Set; - -/** - * 权限逻辑接口 - */ -public interface PermissionService extends BaseService { - - /** - * 根据角色Id获得权限列表 - * - * @param roleId 角色Id - * @return 权限列表 - */ - List listPermissionsByRoleId(Long roleId); - - /** - * 获得某个用户的权限URL列表 - * - * @param userId - * @return - */ - Set findPermissionUrlsByUserId(Long userId); - - /** - * 获得某个用户的用户ID和资源类型 - * - * @param userId - * @param resourceType - * @return - */ - List findPermissionTreeByUserIdAndResourceType(Long userId, String resourceType); - - /** - * 根据角色ID获得权限列表 - * @param roleId - * @return - */ - List findPermissionByRoleId(Long roleId); - - /** - * 获得所有权限,带有等级 - * @return - */ - List findPermissionListWithLevel(); - - /** - * 统计子节点数量 - * @param id - * @return - */ - Integer countChildPermission(Long id); - - /** - * 根据URL获得权限 - * @param url - * @return - */ - Permission findByUrl(String url); -} diff --git a/src/main/java/com/example/hotel/service/PostService.java b/src/main/java/com/example/hotel/service/PostService.java deleted file mode 100755 index 95e00d8..0000000 --- a/src/main/java/com/example/hotel/service/PostService.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.example.hotel.service; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.common.base.BaseService; -import com.example.hotel.dto.PostQueryCondition; -import com.example.hotel.entity.Post; - -/** - *
- *     记录/页面业务逻辑接口
- * 
- */ -public interface PostService extends BaseService { - - /** - * 根据条件获得列表 - * @param condition - * @return - */ - Page findPostByCondition(PostQueryCondition condition, Page page); - - - -} diff --git a/src/main/java/com/example/hotel/service/RecordService.java b/src/main/java/com/example/hotel/service/RecordService.java deleted file mode 100644 index 4cbee1e..0000000 --- a/src/main/java/com/example/hotel/service/RecordService.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.example.hotel.service; - -import com.example.hotel.common.base.BaseService; -import com.example.hotel.entity.Record; - -import java.util.List; - -/** - * 预定 - * @author 言曌 - * @date 2020/4/6 2:00 下午 - */ -public interface RecordService extends BaseService { - - /** - * 根据房间ID和日期列表查询预定 - * - * @param postId - * @param dateList - * @return - */ - List findByPostIdAndRecordDate( Long postId, List dateList); - - /** - * 获得某个房间的预定记录 - * @param postId - * @return - */ - List findByPostId(Long postId); - - /** - * 删除 - * @param postId - * @param userId - * @param dateList - * @return - */ - Integer delete(Long postId, Long userId, List dateList); -} diff --git a/src/main/java/com/example/hotel/service/RolePermissionRefService.java b/src/main/java/com/example/hotel/service/RolePermissionRefService.java deleted file mode 100644 index 05713a7..0000000 --- a/src/main/java/com/example/hotel/service/RolePermissionRefService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.example.hotel.service; - -import com.example.hotel.entity.RolePermissionRef; - -import java.util.List; - - -public interface RolePermissionRefService { - - /** - * 删除某个角色的所有关联 - * - * @param roleId 角色Id - */ - void deleteRefByRoleId(Long roleId); - - /** - * 添加角色和权限关联 - * - * @param rolePermissionRef RolePermissionRef - * @return UserRoleRef - */ - void saveByRolePermissionRef(RolePermissionRef rolePermissionRef); - - /** - * 批量添加 - * - * @param rolePermissionRefs 列表 - */ - void batchSaveByRolePermissionRef(List rolePermissionRefs); - -} diff --git a/src/main/java/com/example/hotel/service/RoleService.java b/src/main/java/com/example/hotel/service/RoleService.java deleted file mode 100755 index 2731807..0000000 --- a/src/main/java/com/example/hotel/service/RoleService.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.example.hotel.service; - -import com.example.hotel.entity.Role; -import com.example.hotel.common.base.BaseService; - -import java.util.List; - -/** - * 角色逻辑接口 - */ -public interface RoleService extends BaseService { - - /** - * 删除某个用户的所有关联 - * - * @param userId 用户Id - */ - void deleteByUserId(Long userId); - - /** - * 根据编号查询单个权限 - * - * @param roleId roleId - * @return Role - */ - Role findByRoleId(Long roleId); - - /** - * 根据编号查询单个权限 - * - * @param roleName roleName - * @return Role - */ - Role findByRoleName(String roleName); - - /** - * 根据用户Id获得角色 - * - * @param userId 用户Id - * @return 角色列表 - */ - Role findByUserId(Long userId); - - /** - * 统计这个角色的用户数 - * - * @param roleId 角色Id - */ - Integer countUserByRoleId(Long roleId); - - /** - * 查询某个用户最大的角色等级 - * @param userId - * @return - */ - Integer findMaxLevelByUserId(Long userId); - - /** - * 查询小于等于该等级的角色 - * @param level - * @return - */ - List findByLessThanLevel(Integer level); - - /** - * 获得用户注册默认角色 - * @return - */ - Role findDefaultRole(); - - /** - * 获得用户注册默认角色 - * @return - */ - Role getMaxRoleByUserId(Long userId); - -} diff --git a/src/main/java/com/example/hotel/service/UserRoleRefService.java b/src/main/java/com/example/hotel/service/UserRoleRefService.java deleted file mode 100644 index 6a4a760..0000000 --- a/src/main/java/com/example/hotel/service/UserRoleRefService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.example.hotel.service; - -import com.example.hotel.entity.UserRoleRef; -import com.example.hotel.common.base.BaseService; - - -public interface UserRoleRefService extends BaseService { - - /** - * 根据用户Id删除 - * - * @param userId 用户Id - */ - void deleteByUserId(Long userId); - - -} diff --git a/src/main/java/com/example/hotel/service/UserService.java b/src/main/java/com/example/hotel/service/UserService.java deleted file mode 100755 index 6712f59..0000000 --- a/src/main/java/com/example/hotel/service/UserService.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.example.hotel.service; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.common.base.BaseService; -import com.example.hotel.entity.User; - -import java.util.List; - -/** - * 用户业务逻辑接口 - */ -public interface UserService extends BaseService { - - /** - * 根据手机号获得用户 - * - * @param userName 手机号 - * @return 用户 - */ - User findByUserName(String userName); - - - /** - * 根据身份证号码查找用户 - * - * @param idCard 身份证号码 - * @return User - */ - User findByIdCard(String idCard); - - /** - * 更新密码 - * - * @param userId 用户Id - * @param password 密码 - */ - void updatePassword(Long userId, String password); - - /** - * 分页获取所有用户 - * - * @param roleName 角色名称 - * @param condition 查询条件 - * @param page 分页信息 - * @return 用户列表 - */ - Page findByRoleAndCondition(String roleName, User condition, Page page); - -} diff --git a/src/main/java/com/example/hotel/service/impl/CategoryServiceImpl.java b/src/main/java/com/example/hotel/service/impl/CategoryServiceImpl.java deleted file mode 100755 index 29d0157..0000000 --- a/src/main/java/com/example/hotel/service/impl/CategoryServiceImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.example.hotel.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.example.hotel.entity.Category; -import com.example.hotel.mapper.CategoryMapper; -import com.example.hotel.mapper.PostMapper; -import com.example.hotel.service.CategoryService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -/** - *
- *     分类业务逻辑实现类
- * 
- * - */ -@Service -public class CategoryServiceImpl implements CategoryService { - - @Autowired - private CategoryMapper categoryMapper; - - @Autowired - private PostMapper postMapper; - - @Override - public BaseMapper getRepository() { - return categoryMapper; - } - - @Override - public QueryWrapper getQueryWrapper(Category category) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (category != null) { - if (StrUtil.isNotBlank(category.getCateName())) { - queryWrapper.like("cate_name", category.getCateName()); - } - } - return queryWrapper; - } - - @Override - public Category insert(Category category) { - categoryMapper.insert(category); - return category; - } - - @Override - public Category update(Category category) { - categoryMapper.updateById(category); - return category; - } - - @Override - public void delete(Long id) { - //2.删除分类 - categoryMapper.deleteById(id); - } - - - @Override - public List findByUserId(Long userId) { - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.eq("user_id", userId); - return categoryMapper.selectList(queryWrapper); - } - - - @Override - public Integer countPostByCateId(Long cateId) { - return postMapper.countPostByCateId(cateId); - } - - @Override - public Category insertOrUpdate(Category entity) { - if (entity.getId() == null) { - insert(entity); - } else { - update(entity); - } - return entity; - } - - @Override - public Integer deleteByUserId(Long userId) { - return categoryMapper.deleteByUserId(userId); - } - - @Override - public List cateIdsToCateList(List cateIds, Long userId) { - List categoryList = this.findByUserId(userId); - List allCateIds = categoryList.stream().map(Category::getId).collect(Collectors.toList()); - List result = new ArrayList<>(); - for(Long id : cateIds) { - if(allCateIds.contains(id)) { - Category category = new Category(); - category.setId(id); - result.add(category); - } - } - return result; - } - - -} diff --git a/src/main/java/com/example/hotel/service/impl/MailServiceImpl.java b/src/main/java/com/example/hotel/service/impl/MailServiceImpl.java deleted file mode 100755 index 4ee510c..0000000 --- a/src/main/java/com/example/hotel/service/impl/MailServiceImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.example.hotel.service.impl; - -import com.example.hotel.service.MailService; -import com.example.hotel.util.SensUtils; -import io.github.biezhi.ome.OhMyEmail; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import javax.mail.MessagingException; - -/** - *
- *     邮件发送业务逻辑实现类
- * 
- * - * @author : saysky - * @date : 2018/1/23 - */ -@Service -public class MailServiceImpl implements MailService { - - @Value("${mail.smtp.host}") - private String host; - - @Value("${mail.smtp.username}") - private String username; - - @Value("${mail.smtp.password}") - private String password; - - @Value("${mail.from.name}") - private String fromName; - - /** - * 发送邮件 - * - * @param to to 接收者 - * @param title subject 标题 - * @param content content 内容 - */ - @Override - public void sendMail(String to, String title, String content) throws MessagingException { - //配置邮件服务器 - SensUtils.configMail(host, username, password); - OhMyEmail.subject(title) - .from(fromName) - .to(to) - .text(content) - .send(); - } -} diff --git a/src/main/java/com/example/hotel/service/impl/OrderServiceImpl.java b/src/main/java/com/example/hotel/service/impl/OrderServiceImpl.java deleted file mode 100644 index 4ae7794..0000000 --- a/src/main/java/com/example/hotel/service/impl/OrderServiceImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.example.hotel.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.entity.Order; -import com.example.hotel.entity.User; -import com.example.hotel.mapper.OrderMapper; -import com.example.hotel.service.OrderService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @author 言曌 - * @date 2020/4/6 2:01 下午 - */ -@Service -public class OrderServiceImpl implements OrderService { - - @Autowired - private OrderMapper orderMapper; - - @Override - public BaseMapper getRepository() { - return orderMapper; - } - - @Override - public QueryWrapper getQueryWrapper(Order order) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (order != null) { - if (order.getUserId() != null) { - queryWrapper.eq("user_id", order.getUserId()); - } - if (order.getPostId() != null) { - queryWrapper.eq("post_id", order.getPostId()); - } - if (StrUtil.isNotBlank(order.getPhone())) { - queryWrapper.eq("phone", order.getPhone()); - } - if (order.getStatus() != null) { - queryWrapper.eq("status", order.getStatus()); - } - if (order.getStartDate() != null) { - queryWrapper.eq("start_date", order.getStartDate()); - } - } - return queryWrapper; - } - - @Override - public Integer getTotalPriceSum(String startDate, String endDate) { - return orderMapper.getTotalPriceSum(startDate, endDate); - } - - @Override - public Page findAll(String startDate, String endDate, Page page) { - return page.setRecords(orderMapper.findAll(startDate, endDate, page)); - } -} diff --git a/src/main/java/com/example/hotel/service/impl/PermissionServiceImpl.java b/src/main/java/com/example/hotel/service/impl/PermissionServiceImpl.java deleted file mode 100644 index ac4aba4..0000000 --- a/src/main/java/com/example/hotel/service/impl/PermissionServiceImpl.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.example.hotel.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.example.hotel.entity.Permission; -import com.example.hotel.mapper.PermissionMapper; -import com.example.hotel.mapper.RolePermissionRefMapper; -import com.example.hotel.service.PermissionService; -import com.example.hotel.util.PermissionUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * 角色业务逻辑实现类 - */ -@Service -public class PermissionServiceImpl implements PermissionService { - - @Autowired - private PermissionMapper permissionMapper; - - @Autowired - private RolePermissionRefMapper rolePermissionRefMapper; - - - @Override - public List listPermissionsByRoleId(Long roleId) { - return permissionMapper.findByRoleId(roleId); - } - - @Override - public Set findPermissionUrlsByUserId(Long userId) { - List permissions = permissionMapper.findPermissionByUserId(userId); - Set urls = permissions.stream().map(p -> p.getUrl()).collect(Collectors.toSet()); - return urls; - } - - @Override - public List findPermissionTreeByUserIdAndResourceType(Long userId, String resourceType) { - List permissions = permissionMapper.findPermissionByUserIdAndResourceType(userId, resourceType); - return PermissionUtil.getPermissionTree(permissions); - } - - @Override - public List findPermissionByRoleId(Long roleId) { - return permissionMapper.findPermissionByRoleId(roleId); - } - - - @Override - public BaseMapper getRepository() { - return permissionMapper; - } - - @Override - public QueryWrapper getQueryWrapper(Permission permission) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (permission != null) { - if (StrUtil.isNotBlank(permission.getResourceType())) { - queryWrapper.eq("resource_type", permission.getResourceType()); - } - if (StrUtil.isNotBlank(permission.getResourceType())) { - queryWrapper.eq("resource_type", permission.getResourceType()); - } - if (StrUtil.isNotBlank(permission.getUrl())) { - queryWrapper.eq("url", permission.getUrl()); - } - if (StrUtil.isNotBlank(permission.getName())) { - queryWrapper.eq("name", permission.getName()); - } - } - return queryWrapper; - } - - @Override - public Permission insertOrUpdate(Permission entity) { - if (entity.getId() == null) { - insert(entity); - } else { - update(entity); - } - return entity; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long id) { - permissionMapper.deleteById(id); - rolePermissionRefMapper.deleteByPermissionId(id); - } - - @Override - public List findPermissionListWithLevel() { - List permissionList = permissionMapper.selectList(null); - permissionList = PermissionUtil.getPermissionList(permissionList); - - // 加空格以展示等级 - for (Permission permission : permissionList) { - for (int i = 1; i < permission.getLevel(); i++) { - permission.setName("    "+permission.getName()); - } - } - return permissionList; - - } - - @Override - public Integer countChildPermission(Long id) { - return permissionMapper.countChildPermission(id); - } - - @Override - public Permission findByUrl(String url) { - return permissionMapper.findByUrl(url); - } - -} diff --git a/src/main/java/com/example/hotel/service/impl/PostServiceImpl.java b/src/main/java/com/example/hotel/service/impl/PostServiceImpl.java deleted file mode 100755 index e4a79b2..0000000 --- a/src/main/java/com/example/hotel/service/impl/PostServiceImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.example.hotel.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.dto.PostQueryCondition; -import com.example.hotel.entity.*; -import com.example.hotel.mapper.*; -import com.example.hotel.service.*; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - - -/** - *
- *     客房业务逻辑实现类
- * 
- */ -@Service -@Slf4j -public class PostServiceImpl implements PostService { - - - @Autowired - private PostMapper postMapper; - - @Override - public Page findPostByCondition(PostQueryCondition condition, Page page) { - List postList = postMapper.findPostByCondition(condition, page); - return page.setRecords(postList); - } - - @Override - public BaseMapper getRepository() { - return postMapper; - } - - @Override - public Post insert(Post post) { - postMapper.insert(post); - return post; - } - - @Override - public Post update(Post post) { - postMapper.updateById(post); - return post; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long postId) { - Post post = this.get(postId); - if (post != null) { - postMapper.deleteById(post.getId()); - } - } - - @Override - public QueryWrapper getQueryWrapper(Post post) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (post != null) { - if (StrUtil.isNotBlank(post.getPostTitle())) { - queryWrapper.like("post_title", post.getPostTitle()); - } - if (StrUtil.isNotBlank(post.getPostContent())) { - queryWrapper.like("post_content", post.getPostContent()); - } - if (post.getPostStatus() != null && post.getPostStatus() != -1) { - queryWrapper.eq("post_status", post.getPostStatus()); - } - } - return queryWrapper; - } - - @Override - public Post insertOrUpdate(Post post) { - if (post.getId() == null) { - insert(post); - } else { - update(post); - } - return post; - } - -} - diff --git a/src/main/java/com/example/hotel/service/impl/RecordServiceImpl.java b/src/main/java/com/example/hotel/service/impl/RecordServiceImpl.java deleted file mode 100644 index c6a9f9a..0000000 --- a/src/main/java/com/example/hotel/service/impl/RecordServiceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.example.hotel.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.example.hotel.entity.Record; -import com.example.hotel.mapper.RecordMapper; -import com.example.hotel.service.RecordService; -import org.apache.commons.collections.ListUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * @author 言曌 - * @date 2020/4/6 2:01 下午 - */ -@Service -public class RecordServiceImpl implements RecordService { - - @Autowired - private RecordMapper recordMapper; - - @Override - public BaseMapper getRepository() { - return recordMapper; - } - - @Override - public QueryWrapper getQueryWrapper(Record record) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (record != null) { - if (record.getUserId() != null) { - queryWrapper.eq("user_id", record.getUserId()); - } - if (record.getPostId() != null) { - queryWrapper.eq("post_id", record.getPostId()); - } - if (record.getRecordDate() != null) { - queryWrapper.eq("record_date", record.getRecordDate()); - } - } - return queryWrapper; - } - - @Override - public List findByPostIdAndRecordDate(Long postId, List dateList) { - return recordMapper.findByPostIdAndRecordDate(postId, dateList); - } - - @Override - public List findByPostId(Long postId) { - return recordMapper.findByPostId(postId); - } - - @Override - public Integer delete(Long postId, Long userId, List dateList) { - if (dateList != null && dateList.size() > 0) { - return recordMapper.delete(postId, userId, dateList); - } - return 0; - } -} diff --git a/src/main/java/com/example/hotel/service/impl/RolePermissionRefServiceImpl.java b/src/main/java/com/example/hotel/service/impl/RolePermissionRefServiceImpl.java deleted file mode 100644 index ebb95e7..0000000 --- a/src/main/java/com/example/hotel/service/impl/RolePermissionRefServiceImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.example.hotel.service.impl; - -import com.example.hotel.entity.RolePermissionRef; -import com.example.hotel.mapper.RolePermissionRefMapper; -import com.example.hotel.service.RolePermissionRefService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class RolePermissionRefServiceImpl implements RolePermissionRefService { - - @Autowired - private RolePermissionRefMapper rolePermissionRefMapper; - - @Override - public void deleteRefByRoleId(Long roleId) { - rolePermissionRefMapper.deleteByRoleId(roleId); - } - - @Override - public void saveByRolePermissionRef(RolePermissionRef rolePermissionRef) { - rolePermissionRefMapper.insert(rolePermissionRef); - } - - @Override - public void batchSaveByRolePermissionRef(List rolePermissionRefs) { - rolePermissionRefMapper.batchInsert(rolePermissionRefs); - } -} \ No newline at end of file diff --git a/src/main/java/com/example/hotel/service/impl/RoleServiceImpl.java b/src/main/java/com/example/hotel/service/impl/RoleServiceImpl.java deleted file mode 100644 index 07881a9..0000000 --- a/src/main/java/com/example/hotel/service/impl/RoleServiceImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.example.hotel.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.example.hotel.entity.Permission; -import com.example.hotel.entity.Role; -import com.example.hotel.entity.RolePermissionRef; -import com.example.hotel.mapper.RoleMapper; -import com.example.hotel.service.RolePermissionRefService; -import com.example.hotel.service.RoleService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.List; - -/** - * 角色业务逻辑实现类 - */ -@Service -public class RoleServiceImpl implements RoleService { - - @Autowired - private RoleMapper roleMapper; - - @Autowired - private RolePermissionRefService rolePermissionRefService; - - @Override - public BaseMapper getRepository() { - return roleMapper; - } - - @Override - public QueryWrapper getQueryWrapper(Role role) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (role != null) { - if (StrUtil.isNotBlank(role.getRole())) { - queryWrapper.eq("role", role.getRole()); - } - if (StrUtil.isNotBlank(role.getDescription())) { - queryWrapper.eq("description", role.getDescription()); - } - } - return queryWrapper; - } - - @Override - public void deleteByUserId(Long userId) { - roleMapper.deleteByUserId(userId); - } - - @Override - public Role findByRoleId(Long roleId) { - return roleMapper.selectById(roleId); - } - - @Override - public Role findByRoleName(String roleName) { - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.eq("role", roleName); - return roleMapper.selectOne(queryWrapper); - } - - @Override - public Role findByUserId(Long userId) { - return roleMapper.findByUserId(userId); - } - - @Override - public Integer countUserByRoleId(Long roleId) { - return roleMapper.countUserByRoleId(roleId); - } - - @Override - public Integer findMaxLevelByUserId(Long userId) { - return roleMapper.findMaxLevelByUserId(userId); - } - - @Override - public List findByLessThanLevel(Integer level) { - return roleMapper.findByLessThanLevel(level); - } - - @Override - public Role findDefaultRole() { - return roleMapper.findDefaultRole(); - } - - @Override - public Role getMaxRoleByUserId(Long userId) { - return null; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public Role insert(Role role) { - roleMapper.insert(role); - if (role.getPermissions() != null && role.getPermissions().size() > 0) { - List rolePermissionRefs = new ArrayList<>(role.getPermissions().size()); - for (Permission permission : role.getPermissions()) { - rolePermissionRefs.add(new RolePermissionRef(role.getId(), permission.getId())); - } - rolePermissionRefService.batchSaveByRolePermissionRef(rolePermissionRefs); - } - return role; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public Role update(Role role) { - roleMapper.updateById(role); - if (role.getPermissions() != null && role.getPermissions().size() > 0) { - // 删除关联 - rolePermissionRefService.deleteRefByRoleId(role.getId()); - // 添加关联 - List rolePermissionRefs = new ArrayList<>(role.getPermissions().size()); - for (Permission permission : role.getPermissions()) { - rolePermissionRefs.add(new RolePermissionRef(role.getId(), permission.getId())); - } - rolePermissionRefService.batchSaveByRolePermissionRef(rolePermissionRefs); - } - return role; - } - - @Override - public Role insertOrUpdate(Role entity) { - if (entity.getId() == null) { - insert(entity); - } else { - update(entity); - } - return entity; - } - -} diff --git a/src/main/java/com/example/hotel/service/impl/UserRoleRefServiceImpl.java b/src/main/java/com/example/hotel/service/impl/UserRoleRefServiceImpl.java deleted file mode 100644 index 6ec0bea..0000000 --- a/src/main/java/com/example/hotel/service/impl/UserRoleRefServiceImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.example.hotel.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.example.hotel.entity.UserRoleRef; -import com.example.hotel.mapper.UserRoleRefMapper; -import com.example.hotel.service.UserRoleRefService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - - -@Service -public class UserRoleRefServiceImpl implements UserRoleRefService { - - @Autowired - private UserRoleRefMapper roleRefMapper; - - - @Override - public void deleteByUserId(Long userId) { - roleRefMapper.deleteByUserId(userId); - } - - @Override - public BaseMapper getRepository() { - return roleRefMapper; - } - - @Override - public QueryWrapper getQueryWrapper(UserRoleRef userRoleRef) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (userRoleRef != null) { - if (userRoleRef.getUserId() != null) { - queryWrapper.eq("user_id", userRoleRef.getUserId()); - } - if (userRoleRef.getRoleId() != null) { - queryWrapper.eq("role_id", userRoleRef.getRoleId()); - } - } - return queryWrapper; - } - -} diff --git a/src/main/java/com/example/hotel/service/impl/UserServiceImpl.java b/src/main/java/com/example/hotel/service/impl/UserServiceImpl.java deleted file mode 100644 index 049a462..0000000 --- a/src/main/java/com/example/hotel/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.example.hotel.service.impl; - -import cn.hutool.core.lang.Validator; -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.example.hotel.dto.JsonResult; -import com.example.hotel.exception.MyBusinessException; -import com.example.hotel.common.constant.CommonConstant; -import com.example.hotel.entity.Role; -import com.example.hotel.mapper.OrderMapper; -import com.example.hotel.mapper.RecordMapper; -import com.example.hotel.mapper.UserMapper; -import com.example.hotel.entity.User; -import com.example.hotel.enums.TrueFalseEnum; -import com.example.hotel.service.PostService; -import com.example.hotel.service.RoleService; -import com.example.hotel.service.UserService; -import com.example.hotel.util.Md5Util; -import com.example.hotel.util.RegexUtil; -import org.apache.commons.lang3.RandomUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; - -/** - * 用户业务逻辑实现类 - */ -@Service -public class UserServiceImpl implements UserService { - - @Autowired - private UserMapper userMapper; - - @Autowired - private RoleService roleService; - - @Autowired - private OrderMapper orderMapper; - - @Autowired - private RecordMapper recordMapper; - - @Override - public User findByUserName(String userName) { - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.eq("user_name", userName); - return userMapper.selectOne(queryWrapper); - } - - @Override - public User findByIdCard(String idCard) { - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.eq("id_card", idCard); - return userMapper.selectOne(queryWrapper); - } - - @Override - public void updatePassword(Long userId, String password) { - User user = new User(); - user.setId(userId); - user.setUserPass(Md5Util.toMd5(password, CommonConstant.PASSWORD_SALT, 10)); - userMapper.updateById(user); - } - - @Override - public Page findByRoleAndCondition(String roleName, User condition, Page page) { - List users = new ArrayList<>(); - if (Objects.equals(roleName, CommonConstant.NONE)) { - users = userMapper.findByCondition(condition, page); - } else { - Role role = roleService.findByRoleName(roleName); - if (role != null) { - users = userMapper.findByRoleIdAndCondition(role.getId(), condition, page); - } - } - return page.setRecords(users); - } - - @Override - public BaseMapper getRepository() { - return userMapper; - } - - @Override - public QueryWrapper getQueryWrapper(User user) { - //对指定字段查询 - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (user != null) { - if (StrUtil.isNotBlank(user.getUserName())) { - queryWrapper.eq("user_name", user.getUserName()); - } - if (StrUtil.isNotBlank(user.getIdCard())) { - queryWrapper.eq("id_card", user.getIdCard()); - } - } - return queryWrapper; - } - - @Override - public User insert(User user) { - // 1.检查长度 - basicCheck(user); - // 2.验证手机号和身份证号码是否存在 - checkUserNameAndIdCard(user); - // 3.添加 - userMapper.insert(user); - return user; - } - - @Override - public User update(User user) { - // 1.检查长度 - basicCheck(user); - // 2.验证手机号和身份证号码是否存在 - checkUserNameAndIdCard(user); - // 3.更新 - userMapper.updateById(user); - return user; - } - - private void checkUserNameAndIdCard(User user) { - //验证手机号和身份证号码是否存在 - if (user.getUserName() != null) { - User nameCheck = findByUserName(user.getUserName()); - Boolean isExist = (user.getId() == null && nameCheck != null) || - (user.getId() != null && nameCheck != null && !Objects.equals(nameCheck.getId(), user.getId())); - if (isExist) { - throw new MyBusinessException("手机号已经存在"); - } - } - if (user.getIdCard() != null) { - User idCardCheck = findByIdCard(user.getIdCard()); - Boolean isExist = (user.getId() == null && idCardCheck != null) || - (user.getId() != null && idCardCheck != null && !Objects.equals(idCardCheck.getId(), user.getId())); - if (isExist) { - throw new MyBusinessException("身份证号码已经存在"); - } - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Long userId) { - //删除用户 - User user = get(userId); - if (user != null) { - // 1.修改用户状态为已删除 - userMapper.deleteById(userId); - // 2.修改用户和角色关联 - roleService.deleteByUserId(userId); - // 3.删除订单 - Map map = new HashMap<>(); - map.put("user_id", userId); - orderMapper.deleteByMap(map); - // 4.删除预定 - recordMapper.deleteByMap(map); - } - } - - @Override - public User insertOrUpdate(User user) { - if (user.getId() == null) { - user.setUserAvatar("/static/images/avatar/" + RandomUtils.nextInt(1, 41) + ".jpeg"); - insert(user); - } else { - update(user); - } - return user; - } - - private void basicCheck(User user) { - String userName = user.getUserName(); - String idCard = user.getIdCard(); - String userDisplayName = user.getUserDisplayName(); - // 1.身份证号码是否合法 - if (StringUtils.isNotEmpty(idCard) && !RegexUtil.isIdCard(idCard)) { - throw new MyBusinessException("身份证号码不合法"); - } - // 2.手机号码长度是否合法 - if (StringUtils.isNotEmpty(userName) && userName.length() != 11) { - throw new MyBusinessException("手机号码不合法"); - } - // 3.姓名长度是否合法 - if (StringUtils.isNotEmpty(userDisplayName) && userDisplayName.length() > 10 || userDisplayName.length() < 2) { - throw new MyBusinessException("姓名长度不合法"); - } - } - - @Override - public User get(Long id) { - User user = userMapper.selectById(id); - return user; - } -}