mirror of
https://github.com/saysky/Hotel
synced 2025-09-18 23:52:30 +08:00
first commit
This commit is contained in:
29
src/main/java/com/example/hotel/Application.java
Executable file
29
src/main/java/com/example/hotel/Application.java
Executable file
@@ -0,0 +1,29 @@
|
||||
package com.example.hotel;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* SENS run!
|
||||
* </pre>
|
||||
*
|
||||
* @author : saysky
|
||||
* @date : 2017/11/14
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
@MapperScan("com.example.hotel.mapper*")
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext context = SpringApplication.run(Application.class, args);
|
||||
String serverPort = context.getEnvironment().getProperty("server.port");
|
||||
log.info("SENS started at http://localhost:" + serverPort);
|
||||
}
|
||||
|
||||
}
|
52
src/main/java/com/example/hotel/common/base/BaseEntity.java
Normal file
52
src/main/java/com/example/hotel/common/base/BaseEntity.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.example.hotel.common.base;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.example.hotel.common.constant.CommonConstant;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2019-08-07 00:28
|
||||
*/
|
||||
@Data
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* ID,自动生成
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 删除状态:1删除,0未删除
|
||||
*/
|
||||
@TableField(value = "del_flag")
|
||||
@TableLogic
|
||||
private Integer delFlag = CommonConstant.STATUS_NORMAL;
|
||||
|
||||
/**
|
||||
* 创建人手机号
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
}
|
233
src/main/java/com/example/hotel/common/base/BaseService.java
Normal file
233
src/main/java/com/example/hotel/common/base/BaseService.java
Normal file
@@ -0,0 +1,233 @@
|
||||
package com.example.hotel.common.base;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
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.vo.SearchVo;
|
||||
import com.example.hotel.dto.QueryCondition;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2019-09-04 22:47
|
||||
*/
|
||||
// JDK8函数式接口注解 仅能包含一个抽象方法
|
||||
public interface BaseService<E, ID extends Serializable> {
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
BaseMapper<E> getRepository();
|
||||
|
||||
/**
|
||||
* 根据ID获取
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
default E get(ID id) {
|
||||
return getRepository().selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default List<E> getAll() {
|
||||
return getRepository().selectList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取总数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default Integer getTotalCount() {
|
||||
return getRepository().selectCount(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
default E insert(E entity) {
|
||||
getRepository().insert(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
default E update(E entity) {
|
||||
getRepository().updateById(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或者更新
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
default E insertOrUpdate(E entity) {
|
||||
try {
|
||||
Object id = entity.getClass().getMethod("getId").invoke(entity);
|
||||
if (id != null) {
|
||||
update(entity);
|
||||
} else {
|
||||
insert(entity);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存与修改
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
default List<E> batchInsert(List<E> list) {
|
||||
for (E e : list) {
|
||||
getRepository().insert(e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据Id删除
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
default void delete(ID id) {
|
||||
getRepository().deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
default void batchDelete(List<ID> ids) {
|
||||
getRepository().deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id批量查询
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
default List<E> findByBatchIds(List<ID> ids) {
|
||||
return getRepository().selectBatchIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
default List<E> findAll() {
|
||||
return getRepository().selectList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件查询获取
|
||||
*
|
||||
* @param queryWrapper
|
||||
* @return
|
||||
*/
|
||||
default List<E> findAll(QueryWrapper<E> queryWrapper) {
|
||||
return getRepository().selectList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据查询条件不分页获取
|
||||
*
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
default List<E> findAll(QueryCondition<E> condition) {
|
||||
E e = condition.getData();
|
||||
|
||||
//对指定字段查询
|
||||
QueryWrapper<E> queryWrapper = getQueryWrapper(e);
|
||||
|
||||
return getRepository().selectList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取
|
||||
*
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
default Page<E> findAll(Page<E> page) {
|
||||
return (Page<E>) getRepository().selectPage(page, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得查询器
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
QueryWrapper<E> getQueryWrapper(E e);
|
||||
|
||||
/**
|
||||
* 根据查询条件分页获取
|
||||
*
|
||||
* @param page
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
default Page<E> findAll(Page<E> page, QueryCondition<E> condition) {
|
||||
E e = condition.getData();
|
||||
SearchVo searchVo = condition.getSearchVo();
|
||||
|
||||
//对指定字段查询
|
||||
QueryWrapper<E> queryWrapper = getQueryWrapper(e);
|
||||
|
||||
//查询日期范围
|
||||
if (searchVo != null) {
|
||||
String startDate = searchVo.getStartDate();
|
||||
String endDate = searchVo.getEndDate();
|
||||
if (StrUtil.isNotBlank(startDate) && StrUtil.isNotBlank(endDate)) {
|
||||
Date start = DateUtil.parse(startDate);
|
||||
Date end = DateUtil.parse(endDate);
|
||||
queryWrapper.between("create_time", start, end);
|
||||
}
|
||||
}
|
||||
return (Page<E>) getRepository().selectPage(page, queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件的结果数
|
||||
*
|
||||
* @param queryWrapper
|
||||
* @return
|
||||
*/
|
||||
default long count(QueryWrapper<E> queryWrapper) {
|
||||
return getRepository().selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
23
src/main/java/com/example/hotel/common/constant/CommonConstant.java
Executable file
23
src/main/java/com/example/hotel/common/constant/CommonConstant.java
Executable file
@@ -0,0 +1,23 @@
|
||||
package com.example.hotel.common.constant;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
* @author 言曌
|
||||
*/
|
||||
public interface CommonConstant {
|
||||
|
||||
/**
|
||||
* 正常状态
|
||||
*/
|
||||
Integer STATUS_NORMAL = 0;
|
||||
|
||||
/**
|
||||
* 用户密码加盐的盐
|
||||
*/
|
||||
String PASSWORD_SALT = "sens";
|
||||
|
||||
/**
|
||||
* none
|
||||
*/
|
||||
String NONE = "none";
|
||||
}
|
58
src/main/java/com/example/hotel/config/MvcConfig.java
Executable file
58
src/main/java/com/example/hotel/config/MvcConfig.java
Executable file
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
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();
|
||||
/*<!-- SQL 执行性能分析,开发环境使用,线上不推荐。 maxTime 指的是 sql 最大执行时长 -->*/
|
||||
performanceInterceptor.setMaxTime(1000);
|
||||
/*<!--SQL是否格式化 默认false-->*/
|
||||
performanceInterceptor.setFormat(true);
|
||||
return performanceInterceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* mybatis-plus分页插件
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
19
src/main/java/com/example/hotel/config/properties/IgnoredUrlsProperties.java
Executable file
19
src/main/java/com/example/hotel/config/properties/IgnoredUrlsProperties.java
Executable file
@@ -0,0 +1,19 @@
|
||||
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<String> urls = new ArrayList<>();
|
||||
}
|
108
src/main/java/com/example/hotel/config/shiro/MyRealm.java
Normal file
108
src/main/java/com/example/hotel/config/shiro/MyRealm.java
Normal file
@@ -0,0 +1,108 @@
|
||||
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<Permission> permissions = permissionService.listPermissionsByRoleId(role.getId());
|
||||
//把权限的URL全部放到authorizationInfo中去
|
||||
Set<String> urls = permissions.stream().map(p -> p.getUrl()).collect(Collectors.toSet());
|
||||
authorizationInfo.addStringPermissions(urls);
|
||||
|
||||
return authorizationInfo;
|
||||
}
|
||||
}
|
111
src/main/java/com/example/hotel/config/shiro/ShiroConfig.java
Normal file
111
src/main/java/com/example/hotel/config/shiro/ShiroConfig.java
Normal file
@@ -0,0 +1,111 @@
|
||||
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<String, Filter> filtersMap = new LinkedHashMap<String, Filter>();
|
||||
//访问权限配置
|
||||
filtersMap.put("requestURL", getURLPathMatchingFilter());
|
||||
shiroFilterFactoryBean.setFilters(filtersMap);
|
||||
|
||||
//拦截器.
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
// 配置不会被拦截的链接 顺序判断
|
||||
List<String> 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();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
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<String> urls = (Set<String>) 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<String, Object> 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()));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台首页控制器
|
||||
* </pre>
|
||||
*/
|
||||
@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<Permission> 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());
|
||||
}
|
||||
|
||||
}
|
44
src/main/java/com/example/hotel/controller/admin/AttachmentController.java
Executable file
44
src/main/java/com/example/hotel/controller/admin/AttachmentController.java
Executable file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台附件控制器
|
||||
* </pre>
|
||||
*
|
||||
* @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<String, Object> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> map = new HashMap<>(1);
|
||||
String path = FileUtil.upload(file);
|
||||
map.put("link", path);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
108
src/main/java/com/example/hotel/controller/admin/CategoryController.java
Executable file
108
src/main/java/com/example/hotel/controller/admin/CategoryController.java
Executable file
@@ -0,0 +1,108 @@
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台分类管理控制器
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
@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<Category> 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<Category> categoryPage = categoryService.findAll(page);
|
||||
model.addAttribute("categories", categoryPage.getRecords());
|
||||
model.addAttribute("pageInfo", PageUtil.convertPageVo(page));
|
||||
return "admin/admin_category";
|
||||
}
|
||||
}
|
170
src/main/java/com/example/hotel/controller/admin/OrderController.java
Executable file
170
src/main/java/com/example/hotel/controller/admin/OrderController.java
Executable file
@@ -0,0 +1,170 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 订单管理控制器
|
||||
* </pre>
|
||||
*/
|
||||
@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<Order> 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<String> 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<String> 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<Order> 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";
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,141 @@
|
||||
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<Permission> 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<Permission> getPermissionList() {
|
||||
//权限列表
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.orderByAsc("sort");
|
||||
List<Permission> 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;
|
||||
}
|
||||
}
|
263
src/main/java/com/example/hotel/controller/admin/PostController.java
Executable file
263
src/main/java/com/example/hotel/controller/admin/PostController.java
Executable file
@@ -0,0 +1,263 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 后台客房管理控制器
|
||||
* </pre>
|
||||
*
|
||||
* @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<Post> posts = postService.findAll(
|
||||
page,
|
||||
new QueryCondition<>(condition, searchVo));
|
||||
|
||||
List<Post> 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<Category> 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<String> 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<Long> ids) {
|
||||
//批量操作
|
||||
//1、防止恶意操作
|
||||
if (ids == null || ids.size() == 0 || ids.size() >= 100) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "参数不合法!");
|
||||
}
|
||||
//2、检查用户权限
|
||||
//客房作者才可以删除
|
||||
List<Post> 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<Category> allCategories = categoryService.findAll();
|
||||
model.addAttribute("categories", allCategories);
|
||||
return "admin/admin_post_edit";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
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("密码重置成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,159 @@
|
||||
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<Role> 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<Permission> 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<Long> currentPermissionIds = permissionService.findPermissionByRoleId(roleId).stream().map(p -> p.getId()).collect(Collectors.toList());
|
||||
model.addAttribute("currentPermissionIds", currentPermissionIds);
|
||||
return "admin/admin_role_edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有权限
|
||||
* @return
|
||||
*/
|
||||
public List<Permission> getPermissionList() {
|
||||
//权限列表
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.orderByAsc("sort");
|
||||
List<Permission> 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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,228 @@
|
||||
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<User> users = userService.findByRoleAndCondition(role, condition, page);
|
||||
|
||||
//角色列表
|
||||
Integer maxLevel = roleService.findMaxLevelByUserId(getLoginUserId());
|
||||
List<Role> 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<User> users = userService.findByRoleAndCondition(role, condition, page);
|
||||
|
||||
//角色列表
|
||||
Integer maxLevel = roleService.findMaxLevelByUserId(getLoginUserId());
|
||||
List<Role> 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<Role> 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<Role> 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<Long> ids) {
|
||||
//批量操作
|
||||
if (ids == null || ids.size() == 0 || ids.size() >= 100) {
|
||||
return JsonResult.error("参数不合法!");
|
||||
}
|
||||
List<User> 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("保存成功");
|
||||
}
|
||||
|
||||
}
|
95
src/main/java/com/example/hotel/controller/common/BaseController.java
Executable file
95
src/main/java/com/example/hotel/controller/common/BaseController.java
Executable file
@@ -0,0 +1,95 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
76
src/main/java/com/example/hotel/controller/common/CommonController.java
Executable file
76
src/main/java/com/example/hotel/controller/common/CommonController.java
Executable file
@@ -0,0 +1,76 @@
|
||||
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";
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
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<Category> 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<Post> postPage = postService.findPostByCondition(condition, page);
|
||||
model.addAttribute("posts", postPage);
|
||||
model.addAttribute("category", category);
|
||||
return "home/category_post";
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,342 @@
|
||||
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<Record> recordList = recordService.findByPostId(id);
|
||||
model.addAttribute("recordList", recordList);
|
||||
|
||||
// 分类列表
|
||||
List<Category> 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<Category> 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<String> dateList = DateUtil.getBetweenDates(start, quantity);
|
||||
// 判断客房是否可以预定
|
||||
List<Record> 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<String> dateList = DateUtil.getBetweenDates(start, quantity);
|
||||
// 判断客房是否可以预定
|
||||
List<Record> 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<Category> categoryList = categoryService.findAll();
|
||||
model.addAttribute("categoryList", categoryList);
|
||||
|
||||
model.addAttribute("user", userService.get(order.getUserId()));
|
||||
return "home/order";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
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<String> dateList = DateUtil.getBetweenDates(start, quantity);
|
||||
condition.setDateList(dateList);
|
||||
condition.setCateId(cateId);
|
||||
Page page = PageUtil.initMpPage(pageNumber, pageSize, sort, order);
|
||||
Page<Post> postPage = postService.findPostByCondition(condition, page);
|
||||
model.addAttribute("posts", postPage);
|
||||
|
||||
// 分类列表
|
||||
List<Category> categoryList = categoryService.findAll();
|
||||
model.addAttribute("categoryList", categoryList);
|
||||
model.addAttribute("quantity", quantity);
|
||||
model.addAttribute("startDate", start);
|
||||
model.addAttribute("cateId", cateId);
|
||||
return "home/index";
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,194 @@
|
||||
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<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
83
src/main/java/com/example/hotel/dto/JsonResult.java
Normal file
83
src/main/java/com/example/hotel/dto/JsonResult.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.example.hotel.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Json格式
|
||||
* </pre>
|
||||
*
|
||||
* @author : saysky
|
||||
* @date : 2018/5/24
|
||||
*/
|
||||
@Data
|
||||
public class JsonResult {
|
||||
|
||||
/**
|
||||
* 返回的状态码,0:失败,1:成功
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 返回信息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 返回的数据
|
||||
*/
|
||||
private Object result;
|
||||
|
||||
/**
|
||||
* 不返回数据的构造方法
|
||||
*
|
||||
* @param code 状态码
|
||||
* @param msg 信息
|
||||
*/
|
||||
public JsonResult(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回数据的构造方法
|
||||
*
|
||||
* @param code 状态码
|
||||
* @param msg 信息
|
||||
* @param result 数据
|
||||
*/
|
||||
public JsonResult(Integer code, String msg, Object result) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回状态码和数据
|
||||
*
|
||||
* @param code 状态码
|
||||
* @param result 数据
|
||||
*/
|
||||
public JsonResult(Integer code, Object result) {
|
||||
this.code = code;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public static JsonResult error(String msg) {
|
||||
return new JsonResult(0, msg);
|
||||
}
|
||||
public static JsonResult error(String msg, Object data) {
|
||||
return new JsonResult(0, msg, data);
|
||||
}
|
||||
public static JsonResult success() {
|
||||
return new JsonResult(1, "操作成功");
|
||||
}
|
||||
|
||||
public static JsonResult success(String msg) {
|
||||
return new JsonResult(1, msg);
|
||||
}
|
||||
|
||||
public static JsonResult success(String msg, Object result) {
|
||||
return new JsonResult(1, msg, result);
|
||||
}
|
||||
}
|
29
src/main/java/com/example/hotel/dto/PostQueryCondition.java
Normal file
29
src/main/java/com/example/hotel/dto/PostQueryCondition.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.example.hotel.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2020/3/12 4:53 下午
|
||||
*/
|
||||
@Data
|
||||
public class PostQueryCondition {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
|
||||
/**
|
||||
* 分类ID
|
||||
*/
|
||||
private Long cateId;
|
||||
|
||||
/**
|
||||
* 预订的日期集合
|
||||
*/
|
||||
private List<String> dateList;
|
||||
}
|
38
src/main/java/com/example/hotel/dto/QueryCondition.java
Normal file
38
src/main/java/com/example/hotel/dto/QueryCondition.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.example.hotel.dto;
|
||||
|
||||
import com.example.hotel.vo.SearchVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 查询封装类
|
||||
* @author 言曌
|
||||
* @date 2019-08-16 13:45
|
||||
*/
|
||||
@Data
|
||||
public class QueryCondition<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 根据字段筛选
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 一般筛选
|
||||
*/
|
||||
private SearchVo searchVo;
|
||||
|
||||
|
||||
public QueryCondition() {
|
||||
}
|
||||
|
||||
public QueryCondition(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public QueryCondition(T data, SearchVo searchVo) {
|
||||
this.data = data;
|
||||
this.searchVo = searchVo;
|
||||
}
|
||||
}
|
33
src/main/java/com/example/hotel/entity/Category.java
Executable file
33
src/main/java/com/example/hotel/entity/Category.java
Executable file
@@ -0,0 +1,33 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 客房分类
|
||||
* </pre>
|
||||
*
|
||||
* @author : saysky
|
||||
* @date : 2017/11/30
|
||||
*/
|
||||
@Data
|
||||
@TableName("category")
|
||||
public class Category extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String cateName;
|
||||
|
||||
/**
|
||||
* 分类排序号
|
||||
*/
|
||||
private Integer cateSort;
|
||||
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String cateDesc;
|
||||
}
|
35
src/main/java/com/example/hotel/entity/Link.java
Executable file
35
src/main/java/com/example/hotel/entity/Link.java
Executable file
@@ -0,0 +1,35 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 友情链接
|
||||
* </pre>
|
||||
*/
|
||||
@Data
|
||||
@TableName("link")
|
||||
public class Link extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 友情链接名称
|
||||
*/
|
||||
private String linkName;
|
||||
|
||||
/**
|
||||
* 友情链接地址
|
||||
*/
|
||||
private String linkUrl;
|
||||
|
||||
/**
|
||||
* 友情链接头像
|
||||
*/
|
||||
private String linkPic;
|
||||
|
||||
/**
|
||||
* 友情链接描述
|
||||
*/
|
||||
private String linkDesc;
|
||||
}
|
63
src/main/java/com/example/hotel/entity/Order.java
Normal file
63
src/main/java/com/example/hotel/entity/Order.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 订单
|
||||
* @author 言曌
|
||||
* @date 2020/4/5 3:25 下午
|
||||
*/
|
||||
@Data
|
||||
@TableName("t_order")
|
||||
public class Order extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 房间ID
|
||||
*/
|
||||
private Long postId;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 住客姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 联系手机
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 入店日期
|
||||
*/
|
||||
private String startDate;
|
||||
|
||||
|
||||
/**
|
||||
* 订单状态:0待支付,1已支付,2已完结
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private Integer price;
|
||||
private Integer totalPrice;
|
||||
private String postTitle;
|
||||
private String postNumber;
|
||||
|
||||
}
|
62
src/main/java/com/example/hotel/entity/Permission.java
Normal file
62
src/main/java/com/example/hotel/entity/Permission.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 权限,后台的菜单
|
||||
* @author example
|
||||
*/
|
||||
@Data
|
||||
@TableName("permission")
|
||||
public class Permission extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 权限名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* pid
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 资源类型
|
||||
*/
|
||||
private String resourceType;
|
||||
|
||||
/**
|
||||
* 请求URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 序号(越小越靠前)
|
||||
*/
|
||||
private Double sort;
|
||||
|
||||
/**
|
||||
* 级别
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 子权限列表
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<Permission> childPermissions;
|
||||
|
||||
}
|
77
src/main/java/com/example/hotel/entity/Post.java
Normal file
77
src/main/java/com/example/hotel/entity/Post.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import com.example.hotel.util.RelativeDateFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Data
|
||||
@TableName("post")
|
||||
public class Post extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 客房标题
|
||||
*/
|
||||
private String postTitle;
|
||||
|
||||
/**
|
||||
* 客房描述
|
||||
*/
|
||||
private String postContent;
|
||||
|
||||
/**
|
||||
* 客房摘要
|
||||
*/
|
||||
private String postSummary;
|
||||
|
||||
/**
|
||||
* 缩略图
|
||||
*/
|
||||
private String postThumbnail;
|
||||
|
||||
/**
|
||||
* 0 正常
|
||||
* 1 已预订
|
||||
* 2 下架
|
||||
*/
|
||||
private Integer postStatus;
|
||||
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 房间编号
|
||||
*/
|
||||
private String number;
|
||||
|
||||
/**
|
||||
* 分类ID
|
||||
*/
|
||||
private Long cateId;
|
||||
|
||||
/**
|
||||
* 图片URL
|
||||
*/
|
||||
private String imgUrl;
|
||||
|
||||
/**
|
||||
* 富文本
|
||||
*/
|
||||
private String postEditor;
|
||||
|
||||
/**
|
||||
* 客房所属分类
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Category category;
|
||||
|
||||
}
|
32
src/main/java/com/example/hotel/entity/Record.java
Normal file
32
src/main/java/com/example/hotel/entity/Record.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 预定记录
|
||||
* @author 言曌
|
||||
* @date 2020/4/5 3:25 下午
|
||||
*/
|
||||
@Data
|
||||
@TableName("record")
|
||||
public class Record extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 房间ID
|
||||
*/
|
||||
private Long postId;
|
||||
|
||||
/**
|
||||
* 入店日期
|
||||
*/
|
||||
private String recordDate;
|
||||
|
||||
|
||||
}
|
49
src/main/java/com/example/hotel/entity/Role.java
Normal file
49
src/main/java/com/example/hotel/entity/Role.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Data
|
||||
@TableName("role")
|
||||
public class Role extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 角色名称:admin,author,subscriber
|
||||
*/
|
||||
private String role;
|
||||
|
||||
/**
|
||||
* 描述:管理员,作者,订阅者
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 级别
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 用户注册默认角色
|
||||
*/
|
||||
private Integer isRegisterDefault;
|
||||
|
||||
/**
|
||||
* 该角色对应的用户数量,非数据库字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private Integer count;
|
||||
|
||||
/**
|
||||
* 当前角色的权限列表
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<Permission> permissions;
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("role_permission_ref")
|
||||
public class RolePermissionRef extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 角色Id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 权限Id
|
||||
*/
|
||||
private Long permissionId;
|
||||
|
||||
public RolePermissionRef() {
|
||||
}
|
||||
|
||||
public RolePermissionRef(Long roleId, Long permissionId) {
|
||||
this.roleId = roleId;
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
}
|
74
src/main/java/com/example/hotel/entity/User.java
Normal file
74
src/main/java/com/example/hotel/entity/User.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
@Data
|
||||
@TableName("user")
|
||||
public class User extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 显示名称
|
||||
*/
|
||||
private String userDisplayName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String userPass;
|
||||
|
||||
/**
|
||||
* 身份证号码
|
||||
*/
|
||||
private String idCard;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String userAvatar;
|
||||
|
||||
/**
|
||||
* 说明
|
||||
*/
|
||||
private String userDesc;
|
||||
|
||||
/**
|
||||
* 最后一次登录时间
|
||||
*/
|
||||
private Date loginLast;
|
||||
|
||||
/**
|
||||
* 0 正常
|
||||
* 1 禁用
|
||||
* 2 已删除
|
||||
*/
|
||||
private Integer status = 0;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String role;
|
||||
|
||||
}
|
34
src/main/java/com/example/hotel/entity/UserRoleRef.java
Normal file
34
src/main/java/com/example/hotel/entity/UserRoleRef.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.example.hotel.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.example.hotel.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 用户和角色关联
|
||||
* @author example
|
||||
*/
|
||||
@Data
|
||||
@TableName("user_role_ref")
|
||||
public class UserRoleRef extends BaseEntity {
|
||||
|
||||
|
||||
/**
|
||||
* 用户Id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色Id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
public UserRoleRef(Long userId, Long roleId) {
|
||||
this.userId = userId;
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public UserRoleRef() {
|
||||
}
|
||||
}
|
37
src/main/java/com/example/hotel/enums/CommonParamsEnum.java
Normal file
37
src/main/java/com/example/hotel/enums/CommonParamsEnum.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* 常用数字
|
||||
*/
|
||||
public enum CommonParamsEnum {
|
||||
|
||||
/**
|
||||
* 数字10
|
||||
*/
|
||||
TEN(10),
|
||||
|
||||
/**
|
||||
* 数字5
|
||||
*/
|
||||
FIVE(5),
|
||||
|
||||
/**
|
||||
* 数字404
|
||||
*/
|
||||
NOT_FOUND(404),
|
||||
|
||||
/**
|
||||
* 数字1024
|
||||
*/
|
||||
BYTE(1024);
|
||||
|
||||
private Integer value;
|
||||
|
||||
CommonParamsEnum(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
40
src/main/java/com/example/hotel/enums/OrderStatusEnum.java
Normal file
40
src/main/java/com/example/hotel/enums/OrderStatusEnum.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 订单状态enum
|
||||
* </pre>
|
||||
*/
|
||||
public enum OrderStatusEnum {
|
||||
|
||||
/**
|
||||
* 待支付
|
||||
*/
|
||||
NOT_PAY(0),
|
||||
|
||||
/**
|
||||
* 已支付
|
||||
*/
|
||||
HAS_PAY(1),
|
||||
|
||||
/**
|
||||
* 已完结
|
||||
*/
|
||||
FINISHED(2),
|
||||
|
||||
/**
|
||||
* 已关闭
|
||||
*/
|
||||
CLOSED(3);
|
||||
|
||||
private Integer code;
|
||||
|
||||
OrderStatusEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* 客房推荐枚举
|
||||
*/
|
||||
public enum PostIsRecommendEnum {
|
||||
|
||||
/**
|
||||
* 真
|
||||
*/
|
||||
TRUE(1),
|
||||
|
||||
/**
|
||||
* 假
|
||||
*/
|
||||
FALSE(0);
|
||||
|
||||
private Integer value;
|
||||
|
||||
PostIsRecommendEnum(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
27
src/main/java/com/example/hotel/enums/PostIsStickyEnum.java
Normal file
27
src/main/java/com/example/hotel/enums/PostIsStickyEnum.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* 客房置顶枚举
|
||||
*/
|
||||
public enum PostIsStickyEnum {
|
||||
|
||||
/**
|
||||
* 真
|
||||
*/
|
||||
TRUE(1),
|
||||
|
||||
/**
|
||||
* 假
|
||||
*/
|
||||
FALSE(0);
|
||||
|
||||
private Integer value;
|
||||
|
||||
PostIsStickyEnum(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
38
src/main/java/com/example/hotel/enums/PostStatusEnum.java
Normal file
38
src/main/java/com/example/hotel/enums/PostStatusEnum.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 客房状态enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : saysky
|
||||
* @date : 2018/7/1
|
||||
*/
|
||||
public enum PostStatusEnum {
|
||||
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
PUBLISHED(0),
|
||||
|
||||
/**
|
||||
* 下架
|
||||
*/
|
||||
DRAFT(1),
|
||||
|
||||
/**
|
||||
* 回收站
|
||||
*/
|
||||
RECYCLE(2);
|
||||
|
||||
private Integer code;
|
||||
|
||||
PostStatusEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
37
src/main/java/com/example/hotel/enums/PostTypeEnum.java
Normal file
37
src/main/java/com/example/hotel/enums/PostTypeEnum.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 客房类型enum
|
||||
* </pre>
|
||||
*
|
||||
* @author : saysky
|
||||
* @date : 2018/7/1
|
||||
*/
|
||||
public enum PostTypeEnum {
|
||||
|
||||
/**
|
||||
* 客房
|
||||
*/
|
||||
POST_TYPE_POST("post"),
|
||||
|
||||
/**
|
||||
* 页面
|
||||
*/
|
||||
POST_TYPE_PAGE("page"),
|
||||
|
||||
/**
|
||||
* 公告
|
||||
*/
|
||||
POST_TYPE_NOTICE("notice");
|
||||
|
||||
private String value;
|
||||
|
||||
PostTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
48
src/main/java/com/example/hotel/enums/ResourceTypeEnum.java
Normal file
48
src/main/java/com/example/hotel/enums/ResourceTypeEnum.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* 资源类型
|
||||
*/
|
||||
public enum ResourceTypeEnum {
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
MENU("menu", "菜单"),
|
||||
|
||||
/**
|
||||
* 接口
|
||||
*/
|
||||
BUTTON("button", "接口"),
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
PAGE("page", "页面");
|
||||
|
||||
|
||||
private String code;
|
||||
|
||||
private String description;
|
||||
|
||||
ResourceTypeEnum(String code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
27
src/main/java/com/example/hotel/enums/ResultCodeEnum.java
Normal file
27
src/main/java/com/example/hotel/enums/ResultCodeEnum.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* 返回结果enum
|
||||
*/
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
SUCCESS(1),
|
||||
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
FAIL(0);
|
||||
|
||||
Integer code;
|
||||
|
||||
ResultCodeEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
35
src/main/java/com/example/hotel/enums/RoleEnum.java
Normal file
35
src/main/java/com/example/hotel/enums/RoleEnum.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 角色枚举
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
public enum RoleEnum {
|
||||
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
ADMIN("admin"),
|
||||
|
||||
/**
|
||||
* 客户
|
||||
*/
|
||||
CUSTOMER("customer"),
|
||||
|
||||
/**
|
||||
* 工作人员
|
||||
*/
|
||||
WORKER("worker");
|
||||
|
||||
private String value;
|
||||
|
||||
RoleEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
27
src/main/java/com/example/hotel/enums/TrueFalseEnum.java
Normal file
27
src/main/java/com/example/hotel/enums/TrueFalseEnum.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* true or false enum
|
||||
*/
|
||||
public enum TrueFalseEnum {
|
||||
|
||||
/**
|
||||
* 真
|
||||
*/
|
||||
TRUE("true"),
|
||||
|
||||
/**
|
||||
* 假
|
||||
*/
|
||||
FALSE("false");
|
||||
|
||||
private String value;
|
||||
|
||||
TrueFalseEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
28
src/main/java/com/example/hotel/enums/UserStatusEnum.java
Normal file
28
src/main/java/com/example/hotel/enums/UserStatusEnum.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.example.hotel.enums;
|
||||
|
||||
/**
|
||||
* 用户状态enum
|
||||
*/
|
||||
public enum UserStatusEnum {
|
||||
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL(0),
|
||||
|
||||
/**
|
||||
* 禁止登录
|
||||
*/
|
||||
BAN(1);
|
||||
|
||||
|
||||
private Integer code;
|
||||
|
||||
UserStatusEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
@@ -0,0 +1,242 @@
|
||||
package com.example.hotel.exception;
|
||||
|
||||
import com.example.hotel.dto.JsonResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 全局异常捕获
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
//错误显示页面
|
||||
public static final String viewName = "common/error/error";
|
||||
|
||||
/**
|
||||
* 是否是ajax请求
|
||||
*/
|
||||
public static boolean isAjax(HttpServletRequest httpRequest) {
|
||||
return (httpRequest.getHeader("X-Requested-With") != null
|
||||
&& "XMLHttpRequest"
|
||||
.equals(httpRequest.getHeader("X-Requested-With").toString()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 400 - Bad Request
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||
public String handleMissingServletRequestParameterException(MissingServletRequestParameterException e, Model model) {
|
||||
log.error("缺少请求参数", e);
|
||||
String message = "【缺少请求参数】" + e.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 400);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 400 - Bad Request
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
public String handleHttpMessageNotReadableException(HttpMessageNotReadableException e, Model model) {
|
||||
log.error("参数解析失败", e);
|
||||
String message = "【参数解析失败】" + e.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 400);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 400 - Bad Request
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public String handleMethodArgumentNotValidException(MethodArgumentNotValidException e, Model model) {
|
||||
log.error("参数验证失败", e);
|
||||
BindingResult result = e.getBindingResult();
|
||||
FieldError error = result.getFieldError();
|
||||
String field = error.getField();
|
||||
String code = error.getDefaultMessage();
|
||||
String message = "【参数验证失败】" + String.format("%s:%s", field, code);
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 400);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 400 - Bad Request
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(BindException.class)
|
||||
public String handleBindException(BindException e, Model model) {
|
||||
log.error("参数绑定失败", e);
|
||||
BindingResult result = e.getBindingResult();
|
||||
FieldError error = result.getFieldError();
|
||||
String field = error.getField();
|
||||
String code = error.getDefaultMessage();
|
||||
String message = "【参数绑定失败】" + String.format("%s:%s", field, code);
|
||||
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 400);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 400 - Bad Request
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(ConstraintViolationException.class)
|
||||
public String handleServiceException(ConstraintViolationException e, Model model) {
|
||||
log.error("参数验证失败", e);
|
||||
Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
|
||||
ConstraintViolation<?> violation = violations.iterator().next();
|
||||
String message = "【参数验证失败】" + violation.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 400);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 400 - Bad Request
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(ValidationException.class)
|
||||
public String handleValidationException(ValidationException e, Model model) {
|
||||
log.error("参数验证失败", e);
|
||||
String message = "【参数验证失败】" + e.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 400);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 404 - Not Found
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
@ExceptionHandler(NoHandlerFoundException.class)
|
||||
public String noHandlerFoundException(NoHandlerFoundException e, Model model) {
|
||||
log.error("Not Found", e);
|
||||
String message = "【页面不存在】" + e.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 404);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 405 - Method Not Allowed
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public String handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e, Model model) {
|
||||
log.error("不支持当前请求方法", e);
|
||||
String message = "【不支持当前请求方法】" + e.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 405);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 415 - Unsupported Media Type
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
|
||||
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
|
||||
public String handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e, Model model) {
|
||||
log.error("不支持当前媒体类型", e);
|
||||
String message = "【不支持当前媒体类型】" + e.getMessage();
|
||||
model.addAttribute("message", message);
|
||||
model.addAttribute("code", 415);
|
||||
return viewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一异常处理
|
||||
*
|
||||
* @param response
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(MyBusinessException.class)
|
||||
@ResponseBody
|
||||
public JsonResult processApiException(HttpServletResponse response,
|
||||
MyBusinessException e) {
|
||||
JsonResult result = new JsonResult(0, e.getMessage());
|
||||
response.setStatus(200);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
log.error("业务异常,提示前端操作不合法", e.getMessage(), e);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取其它异常。包括500
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public ModelAndView defaultErrorHandler(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Exception e, Model model) throws IOException {
|
||||
e.printStackTrace();
|
||||
|
||||
if (isAjax(request)) {
|
||||
ModelAndView mav = new ModelAndView();
|
||||
MappingJackson2JsonView view = new MappingJackson2JsonView();
|
||||
Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
if (e instanceof UnauthorizedException) {
|
||||
attributes.put("msg", "没有权限");
|
||||
} else {
|
||||
attributes.put("msg", e.getMessage());
|
||||
}
|
||||
attributes.put("code", "0");
|
||||
view.setAttributesMap(attributes);
|
||||
mav.setView(view);
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (e instanceof UnauthorizedException) {
|
||||
//请登录
|
||||
log.error("无权访问", e);
|
||||
return new ModelAndView("common/error/403");
|
||||
}
|
||||
//其他异常
|
||||
String message = e.getMessage();
|
||||
model.addAttribute("code", 500);
|
||||
model.addAttribute("message", message);
|
||||
return new ModelAndView("common/error/500");
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package com.example.hotel.exception;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2019-08-09 16:47
|
||||
*/
|
||||
|
||||
public class MyBusinessException extends RuntimeException {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String message;
|
||||
|
||||
|
||||
public MyBusinessException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MyBusinessException(String message) {
|
||||
this.code = 500;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public MyBusinessException(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
31
src/main/java/com/example/hotel/mapper/CategoryMapper.java
Normal file
31
src/main/java/com/example/hotel/mapper/CategoryMapper.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.hotel.entity.Category;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liuyanzhao
|
||||
*/
|
||||
@Mapper
|
||||
public interface CategoryMapper extends BaseMapper<Category> {
|
||||
|
||||
/**
|
||||
* 获得子分类Id列表
|
||||
*
|
||||
* @param pathTrace /138/ 这种格式
|
||||
* @return 子分类Id列表
|
||||
*/
|
||||
List<Long> selectChildCateIds(@Param("pathTrace") String pathTrace);
|
||||
|
||||
/**
|
||||
* 根据用户ID删除
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Integer deleteByUserId(Long userId);
|
||||
}
|
||||
|
40
src/main/java/com/example/hotel/mapper/OrderMapper.java
Normal file
40
src/main/java/com/example/hotel/mapper/OrderMapper.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
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.Order;
|
||||
import com.example.hotel.entity.Post;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liuyanzhao
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderMapper extends BaseMapper<Order> {
|
||||
|
||||
/**
|
||||
* 根据时间范围查询订单
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
List<Order> findAll(@Param("startDate") String startDate,
|
||||
@Param("endDate") String endDate,
|
||||
Page page);
|
||||
|
||||
/**
|
||||
* 根据时间范围查询总金额
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
Integer getTotalPriceSum(@Param("startDate") String startDate,
|
||||
@Param("endDate") String endDate);
|
||||
}
|
||||
|
73
src/main/java/com/example/hotel/mapper/PermissionMapper.java
Normal file
73
src/main/java/com/example/hotel/mapper/PermissionMapper.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.hotel.entity.Permission;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Mapper
|
||||
public interface PermissionMapper extends BaseMapper<Permission> {
|
||||
|
||||
/**
|
||||
* 根据角色Id获得权限列表
|
||||
*
|
||||
* @param roleId 角色Id
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<Permission> findByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 获得某个用户的权限列表
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获得某个用户的权限列表
|
||||
*
|
||||
* @param userId
|
||||
* @param resourceType
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionByUserIdAndResourceType(@Param("userId") Long userId,
|
||||
@Param("resourceType") String resourceType);
|
||||
|
||||
|
||||
/**
|
||||
* 获得权限列表
|
||||
*
|
||||
* @param resourceType
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionByResourceType(Integer resourceType);
|
||||
|
||||
/**
|
||||
* 根据角色ID获得权限列表
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 统计子节点数量
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Integer countChildPermission(Long id);
|
||||
|
||||
/**
|
||||
* 根据URL获得权限
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
Permission findByUrl(String url);
|
||||
}
|
||||
|
36
src/main/java/com/example/hotel/mapper/PostMapper.java
Normal file
36
src/main/java/com/example/hotel/mapper/PostMapper.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
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.Post;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liuyanzhao
|
||||
*/
|
||||
@Mapper
|
||||
public interface PostMapper extends BaseMapper<Post> {
|
||||
|
||||
/**
|
||||
* 根据标签ID查询客房
|
||||
*
|
||||
* @param condition
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
List<Post> findPostByCondition(@Param("condition") PostQueryCondition condition, Page page);
|
||||
|
||||
/**
|
||||
* 统计该分类的客房
|
||||
* @param cateId
|
||||
* @return
|
||||
*/
|
||||
Integer countPostByCateId(Long cateId);
|
||||
|
||||
|
||||
}
|
||||
|
44
src/main/java/com/example/hotel/mapper/RecordMapper.java
Normal file
44
src/main/java/com/example/hotel/mapper/RecordMapper.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.hotel.entity.Record;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liuyanzhao
|
||||
*/
|
||||
@Mapper
|
||||
public interface RecordMapper extends BaseMapper<Record> {
|
||||
|
||||
/**
|
||||
* 根据房间ID和日期列表查询预定
|
||||
*
|
||||
* @param postId
|
||||
* @param dateList
|
||||
* @return
|
||||
*/
|
||||
List<Record> findByPostIdAndRecordDate(@Param("postId") Long postId,
|
||||
@Param("list") List<String> dateList);
|
||||
|
||||
/**
|
||||
* 获得某个房间的预定记录
|
||||
* @param postId
|
||||
* @return
|
||||
*/
|
||||
List<Record> findByPostId(Long postId);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param postId
|
||||
* @param userId
|
||||
* @param dateList
|
||||
* @return
|
||||
*/
|
||||
Integer delete(@Param("postId") Long postId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("list") List<String> dateList);
|
||||
}
|
||||
|
69
src/main/java/com/example/hotel/mapper/RoleMapper.java
Normal file
69
src/main/java/com/example/hotel/mapper/RoleMapper.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.hotel.entity.Role;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleMapper extends BaseMapper<Role> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户Id获得角色
|
||||
*
|
||||
* @param userId 用户Id
|
||||
* @return 角色列表
|
||||
*/
|
||||
Role findByUserId(Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 删除用户和角色管理
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 统计某个角色的用户数
|
||||
*
|
||||
* @param roleId 角色Id
|
||||
* @return 用户数
|
||||
*/
|
||||
Integer countUserByRoleId(Long roleId);
|
||||
|
||||
|
||||
/**
|
||||
* 获得所有角色和对应用户数量
|
||||
* @return
|
||||
*/
|
||||
List<Role> findAllWithCount();
|
||||
|
||||
/**
|
||||
* 查询小于等于该等级的角色
|
||||
* @param level
|
||||
* @return
|
||||
*/
|
||||
List<Role> findByLessThanLevel(Integer level);
|
||||
|
||||
/**
|
||||
* 查询某个用户最大的角色等级
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Integer findMaxLevelByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获得用户注册默认角色
|
||||
* @return
|
||||
*/
|
||||
Role findDefaultRole();
|
||||
}
|
||||
|
@@ -0,0 +1,40 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.hotel.entity.RolePermissionRef;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Mapper
|
||||
public interface RolePermissionRefMapper extends BaseMapper<RolePermissionRef> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据角色Id删除
|
||||
*
|
||||
* @param roleId 角色Id
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer deleteByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据权限Id删除
|
||||
*
|
||||
* @param permissionId 权限Id
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer deleteByPermissionId(Long permissionId);
|
||||
/**
|
||||
* 批量添加
|
||||
*
|
||||
* @param rolePermissionRefList 列表
|
||||
* @return 影响喊你高数
|
||||
*/
|
||||
Integer batchInsert(List<RolePermissionRef> rolePermissionRefList);
|
||||
}
|
||||
|
74
src/main/java/com/example/hotel/mapper/UserMapper.java
Normal file
74
src/main/java/com/example/hotel/mapper/UserMapper.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.hotel.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
/**
|
||||
* 根据角色Id获得用户
|
||||
*
|
||||
* @param roleId 角色Id
|
||||
* @param page 分页信息
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<User> findByRoleId(@Param("roleId") Long roleId, Page page);
|
||||
|
||||
/**
|
||||
* 根据角色Id和条件获得用户
|
||||
*
|
||||
* @param roleId 角色Id
|
||||
* @param user 条件
|
||||
* @param page 分页信息
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<User> findByRoleIdAndCondition(@Param("roleId") Long roleId,
|
||||
@Param("user") User user, Page page);
|
||||
|
||||
/**
|
||||
* 根据条件查询
|
||||
*
|
||||
* @param user 用户
|
||||
* @param page 分页
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<User> findByCondition( @Param("user") User user, Page page);
|
||||
|
||||
/**
|
||||
* 获得今日新增数量
|
||||
* @return
|
||||
*/
|
||||
Integer getTodayCount();
|
||||
|
||||
/**
|
||||
* 获得用户客房数排名
|
||||
* @param limit 查询数量
|
||||
* @return
|
||||
*/
|
||||
List<User> getUserPostRanking(Integer limit);
|
||||
|
||||
/**
|
||||
* 获得最新注册用户
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
List<User> getLatestUser(Integer limit);
|
||||
|
||||
/**
|
||||
* 获得热门用户
|
||||
* @param limit 用户数量
|
||||
* @return
|
||||
*/
|
||||
List<User> getHotUsers(Integer limit);
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package com.example.hotel.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.hotel.entity.UserRoleRef;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserRoleRefMapper extends BaseMapper<UserRoleRef> {
|
||||
|
||||
/**
|
||||
* 根据用户Id删除
|
||||
*
|
||||
* @param userId 用户Id
|
||||
* @return 影响行数
|
||||
*/
|
||||
Integer deleteByUserId(Long userId);
|
||||
}
|
||||
|
50
src/main/java/com/example/hotel/service/CategoryService.java
Executable file
50
src/main/java/com/example/hotel/service/CategoryService.java
Executable file
@@ -0,0 +1,50 @@
|
||||
package com.example.hotel.service;
|
||||
|
||||
|
||||
import com.example.hotel.common.base.BaseService;
|
||||
import com.example.hotel.entity.Category;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分类业务逻辑接口
|
||||
* </pre>
|
||||
*
|
||||
* @author : saysky
|
||||
* @date : 2017/11/30
|
||||
*/
|
||||
public interface CategoryService extends BaseService<Category, Long> {
|
||||
|
||||
/**
|
||||
* 查询所有分类目录,带count和根据level封装name
|
||||
*
|
||||
* @return 返回List集合
|
||||
*/
|
||||
List<Category> 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<Category> cateIdsToCateList(List<Long> cateIds, Long userId);
|
||||
}
|
22
src/main/java/com/example/hotel/service/MailService.java
Executable file
22
src/main/java/com/example/hotel/service/MailService.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package com.example.hotel.service;
|
||||
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 邮件发送业务逻辑接口
|
||||
* </pre>
|
||||
*/
|
||||
public interface MailService {
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param to 接收者
|
||||
* @param title 标题
|
||||
* @param content 内容
|
||||
*/
|
||||
void sendMail(String to, String title, String content) throws MessagingException;
|
||||
|
||||
}
|
35
src/main/java/com/example/hotel/service/OrderService.java
Normal file
35
src/main/java/com/example/hotel/service/OrderService.java
Normal file
@@ -0,0 +1,35 @@
|
||||
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<Order, Long> {
|
||||
|
||||
/**
|
||||
* 根据时间范围查询总金额
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
Integer getTotalPriceSum(String startDate, String endDate);
|
||||
|
||||
/**
|
||||
* 根据时间范围查询
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
Page<Order> findAll(String startDate, String endDate, Page<Order> page);
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
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<Permission, Long> {
|
||||
|
||||
/**
|
||||
* 根据角色Id获得权限列表
|
||||
*
|
||||
* @param roleId 角色Id
|
||||
* @return 权限列表
|
||||
*/
|
||||
List<Permission> listPermissionsByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 获得某个用户的权限URL列表
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
Set<String> findPermissionUrlsByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获得某个用户的用户ID和资源类型
|
||||
*
|
||||
* @param userId
|
||||
* @param resourceType
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionTreeByUserIdAndResourceType(Long userId, String resourceType);
|
||||
|
||||
/**
|
||||
* 根据角色ID获得权限列表
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 获得所有权限,带有等级
|
||||
* @return
|
||||
*/
|
||||
List<Permission> findPermissionListWithLevel();
|
||||
|
||||
/**
|
||||
* 统计子节点数量
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Integer countChildPermission(Long id);
|
||||
|
||||
/**
|
||||
* 根据URL获得权限
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
Permission findByUrl(String url);
|
||||
}
|
24
src/main/java/com/example/hotel/service/PostService.java
Executable file
24
src/main/java/com/example/hotel/service/PostService.java
Executable file
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 记录/页面业务逻辑接口
|
||||
* </pre>
|
||||
*/
|
||||
public interface PostService extends BaseService<Post, Long> {
|
||||
|
||||
/**
|
||||
* 根据条件获得列表
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
Page<Post> findPostByCondition(PostQueryCondition condition, Page<Post> page);
|
||||
|
||||
|
||||
|
||||
}
|
39
src/main/java/com/example/hotel/service/RecordService.java
Normal file
39
src/main/java/com/example/hotel/service/RecordService.java
Normal file
@@ -0,0 +1,39 @@
|
||||
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<Record, Long> {
|
||||
|
||||
/**
|
||||
* 根据房间ID和日期列表查询预定
|
||||
*
|
||||
* @param postId
|
||||
* @param dateList
|
||||
* @return
|
||||
*/
|
||||
List<Record> findByPostIdAndRecordDate( Long postId, List<String> dateList);
|
||||
|
||||
/**
|
||||
* 获得某个房间的预定记录
|
||||
* @param postId
|
||||
* @return
|
||||
*/
|
||||
List<Record> findByPostId(Long postId);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param postId
|
||||
* @param userId
|
||||
* @param dateList
|
||||
* @return
|
||||
*/
|
||||
Integer delete(Long postId, Long userId, List<String> dateList);
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
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<RolePermissionRef> rolePermissionRefs);
|
||||
|
||||
}
|
77
src/main/java/com/example/hotel/service/RoleService.java
Executable file
77
src/main/java/com/example/hotel/service/RoleService.java
Executable file
@@ -0,0 +1,77 @@
|
||||
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<Role, Long> {
|
||||
|
||||
/**
|
||||
* 删除某个用户的所有关联
|
||||
*
|
||||
* @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<Role> findByLessThanLevel(Integer level);
|
||||
|
||||
/**
|
||||
* 获得用户注册默认角色
|
||||
* @return
|
||||
*/
|
||||
Role findDefaultRole();
|
||||
|
||||
/**
|
||||
* 获得用户注册默认角色
|
||||
* @return
|
||||
*/
|
||||
Role getMaxRoleByUserId(Long userId);
|
||||
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.example.hotel.service;
|
||||
|
||||
import com.example.hotel.entity.UserRoleRef;
|
||||
import com.example.hotel.common.base.BaseService;
|
||||
|
||||
|
||||
public interface UserRoleRefService extends BaseService<UserRoleRef, Long> {
|
||||
|
||||
/**
|
||||
* 根据用户Id删除
|
||||
*
|
||||
* @param userId 用户Id
|
||||
*/
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
|
||||
}
|
49
src/main/java/com/example/hotel/service/UserService.java
Executable file
49
src/main/java/com/example/hotel/service/UserService.java
Executable file
@@ -0,0 +1,49 @@
|
||||
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<User, Long> {
|
||||
|
||||
/**
|
||||
* 根据手机号获得用户
|
||||
*
|
||||
* @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<User> findByRoleAndCondition(String roleName, User condition, Page<User> page);
|
||||
|
||||
}
|
112
src/main/java/com/example/hotel/service/impl/CategoryServiceImpl.java
Executable file
112
src/main/java/com/example/hotel/service/impl/CategoryServiceImpl.java
Executable file
@@ -0,0 +1,112 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 分类业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Autowired
|
||||
private PostMapper postMapper;
|
||||
|
||||
@Override
|
||||
public BaseMapper<Category> getRepository() {
|
||||
return categoryMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<Category> getQueryWrapper(Category category) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<Category> 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<Category> 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<Category> cateIdsToCateList(List<Long> cateIds, Long userId) {
|
||||
List<Category> categoryList = this.findByUserId(userId);
|
||||
List<Long> allCateIds = categoryList.stream().map(Category::getId).collect(Collectors.toList());
|
||||
List<Category> result = new ArrayList<>();
|
||||
for(Long id : cateIds) {
|
||||
if(allCateIds.contains(id)) {
|
||||
Category category = new Category();
|
||||
category.setId(id);
|
||||
result.add(category);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
51
src/main/java/com/example/hotel/service/impl/MailServiceImpl.java
Executable file
51
src/main/java/com/example/hotel/service/impl/MailServiceImpl.java
Executable file
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 邮件发送业务逻辑实现类
|
||||
* </pre>
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
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<Order> getRepository() {
|
||||
return orderMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<Order> getQueryWrapper(Order order) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<Order> 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<Order> findAll(String startDate, String endDate, Page<Order> page) {
|
||||
return page.setRecords(orderMapper.findAll(startDate, endDate, page));
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
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<Permission> listPermissionsByRoleId(Long roleId) {
|
||||
return permissionMapper.findByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> findPermissionUrlsByUserId(Long userId) {
|
||||
List<Permission> permissions = permissionMapper.findPermissionByUserId(userId);
|
||||
Set<String> urls = permissions.stream().map(p -> p.getUrl()).collect(Collectors.toSet());
|
||||
return urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> findPermissionTreeByUserIdAndResourceType(Long userId, String resourceType) {
|
||||
List<Permission> permissions = permissionMapper.findPermissionByUserIdAndResourceType(userId, resourceType);
|
||||
return PermissionUtil.getPermissionTree(permissions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permission> findPermissionByRoleId(Long roleId) {
|
||||
return permissionMapper.findPermissionByRoleId(roleId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseMapper<Permission> getRepository() {
|
||||
return permissionMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<Permission> getQueryWrapper(Permission permission) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<Permission> 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<Permission> findPermissionListWithLevel() {
|
||||
List<Permission> 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);
|
||||
}
|
||||
|
||||
}
|
93
src/main/java/com/example/hotel/service/impl/PostServiceImpl.java
Executable file
93
src/main/java/com/example/hotel/service/impl/PostServiceImpl.java
Executable file
@@ -0,0 +1,93 @@
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 客房业务逻辑实现类
|
||||
* </pre>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PostServiceImpl implements PostService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private PostMapper postMapper;
|
||||
|
||||
@Override
|
||||
public Page<Post> findPostByCondition(PostQueryCondition condition, Page<Post> page) {
|
||||
List<Post> postList = postMapper.findPostByCondition(condition, page);
|
||||
return page.setRecords(postList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseMapper<Post> 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<Post> getQueryWrapper(Post post) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<Post> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,64 @@
|
||||
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<Record> getRepository() {
|
||||
return recordMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<Record> getQueryWrapper(Record record) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<Record> 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<Record> findByPostIdAndRecordDate(Long postId, List<String> dateList) {
|
||||
return recordMapper.findByPostIdAndRecordDate(postId, dateList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Record> findByPostId(Long postId) {
|
||||
return recordMapper.findByPostId(postId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer delete(Long postId, Long userId, List<String> dateList) {
|
||||
if (dateList != null && dateList.size() > 0) {
|
||||
return recordMapper.delete(postId, userId, dateList);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
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<RolePermissionRef> rolePermissionRefs) {
|
||||
rolePermissionRefMapper.batchInsert(rolePermissionRefs);
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
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<Role> getRepository() {
|
||||
return roleMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<Role> getQueryWrapper(Role role) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<Role> 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<Role> 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<RolePermissionRef> 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<RolePermissionRef> 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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
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<UserRoleRef> getRepository() {
|
||||
return roleRefMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<UserRoleRef> getQueryWrapper(UserRoleRef userRoleRef) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<UserRoleRef> 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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,199 @@
|
||||
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<User> findByRoleAndCondition(String roleName, User condition, Page<User> page) {
|
||||
List<User> 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<User> getRepository() {
|
||||
return userMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryWrapper<User> getQueryWrapper(User user) {
|
||||
//对指定字段查询
|
||||
QueryWrapper<User> 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<String, Object> 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;
|
||||
}
|
||||
}
|
67
src/main/java/com/example/hotel/util/DateUtil.java
Normal file
67
src/main/java/com/example/hotel/util/DateUtil.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2020/4/5 4:36 下午
|
||||
*/
|
||||
|
||||
public class DateUtil {
|
||||
|
||||
public static final String FORMAT = "yyyy-MM-dd";
|
||||
public static final ThreadLocal<SimpleDateFormat> THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
|
||||
public static List<String> getBetweenDates(String start, int count) {
|
||||
Date startDate = null;
|
||||
SimpleDateFormat sdf = THREAD_LOCAL.get();
|
||||
if (sdf == null) {
|
||||
sdf = new SimpleDateFormat(FORMAT);
|
||||
}
|
||||
try {
|
||||
startDate = sdf.parse(start);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(startDate);
|
||||
c.add(Calendar.DAY_OF_MONTH, count);
|
||||
Date endDate = c.getTime();
|
||||
String end = sdf.format(endDate);
|
||||
return getBetweenDates(start, end);
|
||||
}
|
||||
|
||||
public static List<String> getBetweenDates(String start, String end) {
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
SimpleDateFormat sdf = THREAD_LOCAL.get();
|
||||
if (sdf == null) {
|
||||
sdf = new SimpleDateFormat(FORMAT);
|
||||
}
|
||||
Date start_date = sdf.parse(start);
|
||||
Date end_date = sdf.parse(end);
|
||||
Calendar tempStart = Calendar.getInstance();
|
||||
tempStart.setTime(start_date);
|
||||
Calendar tempEnd = Calendar.getInstance();
|
||||
tempEnd.setTime(end_date);
|
||||
while (tempStart.before(tempEnd)) {
|
||||
result.add(sdf.format(tempStart.getTime()));
|
||||
tempStart.add(Calendar.DAY_OF_YEAR, 1);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getBetweenDates("2020-04-05", 1));
|
||||
}
|
||||
|
||||
}
|
81
src/main/java/com/example/hotel/util/FileUtil.java
Normal file
81
src/main/java/com/example/hotel/util/FileUtil.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import com.example.hotel.exception.MyBusinessException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2020/3/8 5:45 下午
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
/**
|
||||
* 上传文件返回URL
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String upload(MultipartFile file) {
|
||||
String path = "";
|
||||
try {
|
||||
//用户目录
|
||||
final StrBuilder uploadPath = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
uploadPath.append("/sens/upload/" + DateUtil.thisYear()).append("/").append(DateUtil.thisMonth() + 1).append("/");
|
||||
final File mediaPath = new File(uploadPath.toString());
|
||||
if (!mediaPath.exists()) {
|
||||
if (!mediaPath.mkdirs()) {
|
||||
throw new MyBusinessException("上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
//不带后缀
|
||||
String nameWithOutSuffix = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf('.')).replaceAll(" ", "_").replaceAll(",", "");
|
||||
|
||||
//文件后缀
|
||||
final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1);
|
||||
|
||||
//带后缀
|
||||
String fileName = nameWithOutSuffix + "." + fileSuffix;
|
||||
|
||||
//判断文件名是否已存在
|
||||
File descFile = new File(mediaPath.getAbsoluteFile(), fileName);
|
||||
int i = 1;
|
||||
while (descFile.exists()) {
|
||||
nameWithOutSuffix = nameWithOutSuffix + "(" + i + ")";
|
||||
descFile = new File(mediaPath.getAbsoluteFile(), nameWithOutSuffix + "." + fileSuffix);
|
||||
i++;
|
||||
}
|
||||
file.transferTo(descFile);
|
||||
|
||||
//文件原路径
|
||||
final StrBuilder fullPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
fullPath.append("/");
|
||||
fullPath.append(nameWithOutSuffix + "." + fileSuffix);
|
||||
|
||||
//压缩文件路径
|
||||
final StrBuilder fullSmallPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
fullSmallPath.append("/");
|
||||
fullSmallPath.append(nameWithOutSuffix);
|
||||
fullSmallPath.append("_small.");
|
||||
fullSmallPath.append(fileSuffix);
|
||||
|
||||
//映射路径
|
||||
final StrBuilder filePath = new StrBuilder("/upload/");
|
||||
filePath.append(DateUtil.thisYear());
|
||||
filePath.append("/");
|
||||
filePath.append(DateUtil.thisMonth() + 1);
|
||||
filePath.append("/");
|
||||
filePath.append(nameWithOutSuffix + "." + fileSuffix);
|
||||
path = filePath.toString();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
57
src/main/java/com/example/hotel/util/IpInfoUtil.java
Executable file
57
src/main/java/com/example/hotel/util/IpInfoUtil.java
Executable file
@@ -0,0 +1,57 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Slf4j
|
||||
public class IpInfoUtil {
|
||||
|
||||
/**
|
||||
* 获取客户端IP地址
|
||||
* @param request 请求
|
||||
* @return
|
||||
*/
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
if ("127.0.0.1".equals(ip)) {
|
||||
//根据网卡取本机配置的IP
|
||||
InetAddress inet = null;
|
||||
try {
|
||||
inet = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ip = inet.getHostAddress();
|
||||
}
|
||||
}
|
||||
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
||||
if (ip != null && ip.length() > 15) {
|
||||
if (ip.indexOf(",") > 0) {
|
||||
ip = ip.substring(0, ip.indexOf(","));
|
||||
}
|
||||
}
|
||||
if("0:0:0:0:0:0:0:1".equals(ip)){
|
||||
ip = "127.0.0.1";
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
|
||||
}
|
74
src/main/java/com/example/hotel/util/Md5Util.java
Executable file
74
src/main/java/com/example/hotel/util/Md5Util.java
Executable file
@@ -0,0 +1,74 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import org.apache.shiro.crypto.hash.Md5Hash;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* 获取文件hash
|
||||
*/
|
||||
public class Md5Util {
|
||||
|
||||
|
||||
/**
|
||||
* shiro的md5加密
|
||||
*
|
||||
* @param pwd 密码
|
||||
* @param salt 盐
|
||||
* @param i 加密次数
|
||||
* @return 加密后字符串
|
||||
*/
|
||||
public static String toMd5(String pwd, String salt, int i) {
|
||||
Md5Hash toMd5 = new Md5Hash(pwd, salt, i);
|
||||
return toMd5.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算文件MD5编码
|
||||
*
|
||||
* @param file file
|
||||
* @return byte
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
private static byte[] createChecksum(MultipartFile file) throws Exception {
|
||||
final InputStream fis = file.getInputStream();
|
||||
|
||||
final byte[] buffer = new byte[1024];
|
||||
final MessageDigest complete = MessageDigest.getInstance("MD5");
|
||||
int numRead;
|
||||
|
||||
do {
|
||||
numRead = fis.read(buffer);
|
||||
if (numRead > 0) {
|
||||
complete.update(buffer, 0, numRead);
|
||||
}
|
||||
} while (numRead != -1);
|
||||
|
||||
fis.close();
|
||||
return complete.digest();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成文件hash值
|
||||
*
|
||||
* @param file file
|
||||
* @return String
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public static String getMD5Checksum(MultipartFile file) throws Exception {
|
||||
final byte[] b = createChecksum(file);
|
||||
StrBuilder result = new StrBuilder();
|
||||
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
}
|
||||
}
|
57
src/main/java/com/example/hotel/util/ObjectUtil.java
Executable file
57
src/main/java/com/example/hotel/util/ObjectUtil.java
Executable file
@@ -0,0 +1,57 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import org.springframework.cglib.beans.BeanMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
public class ObjectUtil {
|
||||
|
||||
public static String mapToString(Map<String, String[]> paramMap){
|
||||
|
||||
if (paramMap == null) {
|
||||
return "";
|
||||
}
|
||||
Map<String, Object> params = new HashMap<>(16);
|
||||
for (Map.Entry<String, String[]> param : paramMap.entrySet()) {
|
||||
|
||||
String key = param.getKey();
|
||||
String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
|
||||
String obj = StrUtil.endWithIgnoreCase(param.getKey(), "password") ? "密码隐藏" : paramValue;
|
||||
params.put(key,obj);
|
||||
}
|
||||
return new Gson().toJson(params);
|
||||
}
|
||||
|
||||
public static String mapToStringAll(Map<String, String[]> paramMap){
|
||||
|
||||
if (paramMap == null) {
|
||||
return "";
|
||||
}
|
||||
Map<String, Object> params = new HashMap<>(16);
|
||||
for (Map.Entry<String, String[]> param : paramMap.entrySet()) {
|
||||
|
||||
String key = param.getKey();
|
||||
String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
|
||||
params.put(key, paramValue);
|
||||
}
|
||||
return new Gson().toJson(params);
|
||||
}
|
||||
|
||||
public static <T> Map<String, Object> beanToMap(T bean) {
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
if (bean != null) {
|
||||
BeanMap beanMap = BeanMap.create(bean);
|
||||
for (Object key : beanMap.keySet()) {
|
||||
map.put(key+"", beanMap.get(key));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
148
src/main/java/com/example/hotel/util/PageUtil.java
Executable file
148
src/main/java/com/example/hotel/util/PageUtil.java
Executable file
@@ -0,0 +1,148 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.hotel.vo.PageVo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
public class PageUtil {
|
||||
|
||||
/**
|
||||
* 最大分页大小
|
||||
*/
|
||||
public static final int MAX_PAGE_SIZE = 100;
|
||||
|
||||
/**
|
||||
* mybatis分页封装
|
||||
*
|
||||
* @param pageNumber 页码
|
||||
* @param pageSize 页大小
|
||||
* @param sort 排序字段
|
||||
* @param order 倒序/升序
|
||||
* @return
|
||||
*/
|
||||
public static Page initMpPage(long pageNumber, long pageSize, String sort, String order) {
|
||||
|
||||
Page p = null;
|
||||
if (StrUtil.isNotBlank(sort)) {
|
||||
//驼峰法转下划线, createTime -> create_time
|
||||
sort = camelToUnderline(sort);
|
||||
}
|
||||
|
||||
if (pageNumber < 1) {
|
||||
pageNumber = 1;
|
||||
}
|
||||
if (pageSize < 1) {
|
||||
pageSize = 10;
|
||||
}
|
||||
if (pageSize > MAX_PAGE_SIZE) {
|
||||
pageSize = MAX_PAGE_SIZE;
|
||||
}
|
||||
if (StrUtil.isNotBlank(sort)) {
|
||||
Boolean isAsc = false;
|
||||
if (StrUtil.isBlank(order)) {
|
||||
isAsc = false;
|
||||
} else {
|
||||
if ("desc".equals(order.toLowerCase())) {
|
||||
isAsc = false;
|
||||
} else if ("asc".equals(order.toLowerCase())) {
|
||||
isAsc = true;
|
||||
}
|
||||
}
|
||||
p = new Page(pageNumber, pageSize);
|
||||
if (isAsc) {
|
||||
p.setAsc(sort);
|
||||
} else {
|
||||
p.setDesc(sort);
|
||||
}
|
||||
} else {
|
||||
p = new Page(pageNumber, pageSize);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* List 手动分页
|
||||
*
|
||||
* @param page
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public static List listToPage(PageVo page, List list) {
|
||||
|
||||
long pageNumber = page.getPage() - 1;
|
||||
long pageSize = page.getSize();
|
||||
|
||||
if (pageNumber < 0) {
|
||||
pageNumber = 0;
|
||||
}
|
||||
if (pageSize < 1) {
|
||||
pageSize = 10;
|
||||
}
|
||||
|
||||
long fromIndex = pageNumber * pageSize;
|
||||
long toIndex = pageNumber * pageSize + pageSize;
|
||||
|
||||
if (fromIndex > list.size()) {
|
||||
return new ArrayList();
|
||||
} else if (toIndex >= list.size()) {
|
||||
return list.subList((int) fromIndex, list.size());
|
||||
} else {
|
||||
return list.subList((int) fromIndex, (int) toIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰转下划线
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static String camelToUnderline(String str) {
|
||||
if (str == null || str.trim().isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
int len = str.length();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
sb.append(str.substring(0, 1).toLowerCase());
|
||||
for (int i = 1; i < len; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (Character.isUpperCase(c)) {
|
||||
sb.append("_");
|
||||
sb.append(Character.toLowerCase(c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设计缺陷,前端无法获取mybatis-plus的分页page中的pages,所以自己封装一个PageVO
|
||||
* 同时将分页信息塞到PageVo中
|
||||
*
|
||||
* @param page mybatis-plus分页类
|
||||
* @return
|
||||
*/
|
||||
public static PageVo convertPageVo(Page page) {
|
||||
PageVo pageVo = new PageVo();
|
||||
pageVo.setSize(page.getSize());
|
||||
pageVo.setTotal(page.getTotal());
|
||||
pageVo.setCurrent(page.getCurrent());
|
||||
pageVo.setPages(page.getPages());
|
||||
List<OrderItem> orderItems = page.getOrders();
|
||||
if (orderItems != null && orderItems.size() > 0) {
|
||||
pageVo.setSort(orderItems.get(0).getColumn());
|
||||
pageVo.setOrder(orderItems.get(0).isAsc() ? "asc" : "desc");
|
||||
}
|
||||
return pageVo;
|
||||
}
|
||||
|
||||
}
|
108
src/main/java/com/example/hotel/util/PermissionUtil.java
Executable file
108
src/main/java/com/example/hotel/util/PermissionUtil.java
Executable file
@@ -0,0 +1,108 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import com.example.hotel.entity.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 拼装菜单
|
||||
*/
|
||||
public class PermissionUtil {
|
||||
|
||||
/**
|
||||
* 获取组装好的菜单
|
||||
* 以树的形式显示
|
||||
*
|
||||
* @param permissionsRoot permissionsRoot
|
||||
* @return List
|
||||
*/
|
||||
public static List<Permission> getPermissionTree(List<Permission> permissionsRoot) {
|
||||
List<Permission> permissionsResult = new ArrayList<>();
|
||||
|
||||
for (Permission permission : permissionsRoot) {
|
||||
if (permission.getPid() == 0) {
|
||||
permissionsResult.add(permission);
|
||||
}
|
||||
}
|
||||
|
||||
for (Permission permission : permissionsResult) {
|
||||
permission.setChildPermissions(getChildTree(permission.getId(), permissionsRoot));
|
||||
}
|
||||
return permissionsResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单的子菜单
|
||||
*
|
||||
* @param id 菜单编号
|
||||
* @param permissionsRoot permissionsRoot
|
||||
* @return List
|
||||
*/
|
||||
private static List<Permission> getChildTree(Long id, List<Permission> permissionsRoot) {
|
||||
List<Permission> permissionsChild = new ArrayList<>();
|
||||
for (Permission permission : permissionsRoot) {
|
||||
if (permission.getPid() != 0) {
|
||||
if (permission.getPid().equals(id)) {
|
||||
permissionsChild.add(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Permission permission : permissionsChild) {
|
||||
if (permission.getPid() != 0) {
|
||||
permission.setChildPermissions(getChildTree(permission.getId(), permissionsRoot));
|
||||
}
|
||||
}
|
||||
if (permissionsChild.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return permissionsChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组装好的菜单,
|
||||
*
|
||||
* @param permissionsRoot permissionsRoot
|
||||
* @return List
|
||||
*/
|
||||
public static List<Permission> getPermissionList(List<Permission> permissionsRoot) {
|
||||
List<Permission> permissionsResult = new ArrayList<>();
|
||||
|
||||
for (Permission permission : permissionsRoot) {
|
||||
if (permission.getPid() == 0) {
|
||||
permission.setLevel(1);
|
||||
permissionsResult.add(permission);
|
||||
permissionsResult.addAll(getChildList(permission, permissionsRoot));
|
||||
}
|
||||
}
|
||||
return permissionsResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单的子菜单
|
||||
*
|
||||
* @param parentPermission 菜单编号
|
||||
* @param permissionsRoot permissionsRoot
|
||||
* @return List
|
||||
*/
|
||||
private static List<Permission> getChildList(Permission parentPermission, List<Permission> permissionsRoot) {
|
||||
List<Permission> permissionsChild = new ArrayList<>();
|
||||
for (Permission permission : permissionsRoot) {
|
||||
if (permission.getPid() != 0) {
|
||||
if (permission.getPid().equals(parentPermission.getId())) {
|
||||
permission.setLevel(parentPermission.getLevel() + 1);
|
||||
permissionsChild.add(permission);
|
||||
List<Permission> tempList = getChildList(permission, permissionsRoot);
|
||||
tempList.sort((a, b) -> (int) (b.getSort() - a.getSort()));
|
||||
permissionsChild.addAll(tempList);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (permissionsChild.size() == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return permissionsChild;
|
||||
}
|
||||
|
||||
}
|
62
src/main/java/com/example/hotel/util/RegexUtil.java
Normal file
62
src/main/java/com/example/hotel/util/RegexUtil.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2020/3/8 1:55 下午
|
||||
*/
|
||||
|
||||
public class RegexUtil {
|
||||
|
||||
/**
|
||||
* 判断Email合法性
|
||||
*
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String email) {
|
||||
if (email == null) {
|
||||
return false;
|
||||
}
|
||||
String rule = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
|
||||
Pattern pattern = Pattern.compile(rule);
|
||||
Matcher matcher = pattern.matcher(email);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为合法身份证号码
|
||||
* @param idCard
|
||||
* @return
|
||||
*/
|
||||
public static boolean isIdCard(String idCard) {
|
||||
if(idCard == null) {
|
||||
return false;
|
||||
}
|
||||
return idCard.length() == 15 || idCard.length() == 18;
|
||||
}
|
||||
|
||||
public static List<String> getImgSrc(String htmlStr) {
|
||||
String img = "";
|
||||
Pattern imgPattern;
|
||||
Matcher imgMatcher;
|
||||
List<String> pics = new ArrayList<>();
|
||||
String imgReg = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
|
||||
imgPattern = Pattern.compile(imgReg, Pattern.CASE_INSENSITIVE);
|
||||
imgMatcher = imgPattern.matcher(htmlStr);
|
||||
while (imgMatcher.find()) {
|
||||
img = img + "," + imgMatcher.group();
|
||||
Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
|
||||
while (m.find()) {
|
||||
pics.add(m.group(1));
|
||||
}
|
||||
}
|
||||
return pics;
|
||||
}
|
||||
|
||||
|
||||
}
|
78
src/main/java/com/example/hotel/util/RelativeDateFormat.java
Normal file
78
src/main/java/com/example/hotel/util/RelativeDateFormat.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 言曌
|
||||
* @date 2020/3/10 9:48 下午
|
||||
*/
|
||||
|
||||
public class RelativeDateFormat {
|
||||
|
||||
private static final long ONE_MINUTE = 60000L;
|
||||
private static final long ONE_HOUR = 3600000L;
|
||||
private static final long ONE_DAY = 86400000L;
|
||||
private static final long ONE_WEEK = 604800000L;
|
||||
|
||||
private static final String ONE_SECOND_AGO = "秒前";
|
||||
private static final String ONE_MINUTE_AGO = "分钟前";
|
||||
private static final String ONE_HOUR_AGO = "小时前";
|
||||
private static final String ONE_DAY_AGO = "天前";
|
||||
private static final String ONE_MONTH_AGO = "月前";
|
||||
private static final String ONE_YEAR_AGO = "年前";
|
||||
|
||||
public static String format(Date date) {
|
||||
long delta = System.currentTimeMillis() - date.getTime();
|
||||
if (delta < 1L * ONE_MINUTE) {
|
||||
long seconds = toSeconds(delta);
|
||||
return (seconds <= 0 ? 1 : seconds) + ONE_SECOND_AGO;
|
||||
}
|
||||
if (delta < 45L * ONE_MINUTE) {
|
||||
long minutes = toMinutes(delta);
|
||||
return (minutes <= 0 ? 1 : minutes) + ONE_MINUTE_AGO;
|
||||
}
|
||||
if (delta < 24L * ONE_HOUR) {
|
||||
long hours = toHours(delta);
|
||||
return (hours <= 0 ? 1 : hours) + ONE_HOUR_AGO;
|
||||
}
|
||||
if (delta < 48L * ONE_HOUR) {
|
||||
return "昨天";
|
||||
}
|
||||
if (delta < 30L * ONE_DAY) {
|
||||
long days = toDays(delta);
|
||||
return (days <= 0 ? 1 : days) + ONE_DAY_AGO;
|
||||
}
|
||||
if (delta < 12L * 4L * ONE_WEEK) {
|
||||
long months = toMonths(delta);
|
||||
return (months <= 0 ? 1 : months) + ONE_MONTH_AGO;
|
||||
} else {
|
||||
long years = toYears(delta);
|
||||
return (years <= 0 ? 1 : years) + ONE_YEAR_AGO;
|
||||
}
|
||||
}
|
||||
|
||||
private static long toSeconds(long date) {
|
||||
return date / 1000L;
|
||||
}
|
||||
|
||||
private static long toMinutes(long date) {
|
||||
return toSeconds(date) / 60L;
|
||||
}
|
||||
|
||||
private static long toHours(long date) {
|
||||
return toMinutes(date) / 60L;
|
||||
}
|
||||
|
||||
private static long toDays(long date) {
|
||||
return toHours(date) / 24L;
|
||||
}
|
||||
|
||||
private static long toMonths(long date) {
|
||||
return toDays(date) / 30L;
|
||||
}
|
||||
|
||||
private static long toYears(long date) {
|
||||
return toMonths(date) / 365L;
|
||||
}
|
||||
}
|
101
src/main/java/com/example/hotel/util/Response.java
Normal file
101
src/main/java/com/example/hotel/util/Response.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
public class Response<T> {
|
||||
|
||||
private Boolean success;
|
||||
|
||||
private String message;
|
||||
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private Integer status = 200;
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
public Response(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public Response(Boolean success, String message) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Response(Boolean success, String message, T data) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Response(Boolean success, Integer status, String message, T data) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
public static <T> Response<T> yes() {
|
||||
return new Response(true, 200, "成功", null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> yes(T data) {
|
||||
return new Response(true, 200, "成功", data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> yes(String message, T data) {
|
||||
return new Response(true, 200, message, data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> no() {
|
||||
return new Response(false, 500, "失败", null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> no(String message) {
|
||||
return new Response(false, 500, message, null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> no(Integer status, String message) {
|
||||
return new Response(false, status, message, null);
|
||||
}
|
||||
|
||||
public Boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
50
src/main/java/com/example/hotel/util/SensUtils.java
Executable file
50
src/main/java/com/example/hotel/util/SensUtils.java
Executable file
@@ -0,0 +1,50 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import io.github.biezhi.ome.OhMyEmail;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 常用工具
|
||||
* </pre>
|
||||
*/
|
||||
@Slf4j
|
||||
public class SensUtils {
|
||||
|
||||
/**
|
||||
* 配置邮件
|
||||
*
|
||||
* @param smtpHost smtpHost
|
||||
* @param userName 邮件地址
|
||||
* @param password password
|
||||
*/
|
||||
public static void configMail(String smtpHost, String userName, String password) {
|
||||
Properties properties = OhMyEmail.defaultConfig(false);
|
||||
properties.setProperty("mail.smtp.host", smtpHost);
|
||||
OhMyEmail.config(properties, userName, password);
|
||||
}
|
||||
|
||||
|
||||
public static String listToStr(List<String> list) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String str : list) {
|
||||
stringBuilder.append(str).append(",");
|
||||
}
|
||||
String temp = stringBuilder.toString();
|
||||
if (temp.length() > 0) {
|
||||
return temp.substring(0, temp.length() - 1);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("11");
|
||||
list.add("22");
|
||||
list.add("13");
|
||||
System.out.println(listToStr(list));
|
||||
}
|
||||
|
||||
}
|
49
src/main/java/com/example/hotel/util/SpringUtil.java
Executable file
49
src/main/java/com/example/hotel/util/SpringUtil.java
Executable file
@@ -0,0 +1,49 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* 获取applicationContext
|
||||
*
|
||||
* @return ApplicationContext
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (SpringUtil.applicationContext == null) {
|
||||
SpringUtil.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过name获取 Bean.
|
||||
*
|
||||
* @param name name
|
||||
* @return Object
|
||||
*/
|
||||
public static Object getBean(String name) {
|
||||
return getApplicationContext().getBean(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过class获取Bean
|
||||
*
|
||||
* @param clazz clazz
|
||||
* @param <T> <T>
|
||||
* @return T
|
||||
*/
|
||||
public static <T> T getBean(Class<T> clazz) {
|
||||
return getApplicationContext().getBean(clazz);
|
||||
}
|
||||
}
|
44
src/main/java/com/example/hotel/util/ThreadPoolUtil.java
Executable file
44
src/main/java/com/example/hotel/util/ThreadPoolUtil.java
Executable file
@@ -0,0 +1,44 @@
|
||||
package com.example.hotel.util;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
public class ThreadPoolUtil {
|
||||
|
||||
/**
|
||||
* 线程缓冲队列
|
||||
*/
|
||||
private static BlockingQueue<Runnable> bqueue = new ArrayBlockingQueue<Runnable>(100);
|
||||
/**
|
||||
* 核心线程数,会一直存活,即使没有任务,线程池也会维护线程的最少数量
|
||||
*/
|
||||
private static final int SIZE_CORE_POOL = 5;
|
||||
/**
|
||||
* 线程池维护线程的最大数量
|
||||
*/
|
||||
private static final int SIZE_MAX_POOL = 10;
|
||||
/**
|
||||
* 线程池维护线程所允许的空闲时间
|
||||
*/
|
||||
private static final long ALIVE_TIME = 2000;
|
||||
|
||||
private static ThreadPoolExecutor pool = new ThreadPoolExecutor(SIZE_CORE_POOL, SIZE_MAX_POOL, ALIVE_TIME, TimeUnit.MILLISECONDS, bqueue, new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
|
||||
static {
|
||||
|
||||
pool.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
public static ThreadPoolExecutor getPool() {
|
||||
return pool;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(pool.getPoolSize());
|
||||
}
|
||||
}
|
68
src/main/java/com/example/hotel/vo/PageVo.java
Executable file
68
src/main/java/com/example/hotel/vo/PageVo.java
Executable file
@@ -0,0 +1,68 @@
|
||||
package com.example.hotel.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Data
|
||||
public class PageVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 页号
|
||||
*/
|
||||
private long page = 1;
|
||||
|
||||
/**
|
||||
* 页大小
|
||||
*/
|
||||
private long size = 10;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String sort = "create_time";
|
||||
|
||||
/**
|
||||
* 排序方式 asc/desc
|
||||
*/
|
||||
private String order = "desc";
|
||||
|
||||
/**
|
||||
* 当前页码
|
||||
*/
|
||||
private long current;
|
||||
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
private long total;
|
||||
|
||||
/**
|
||||
* 页数
|
||||
*/
|
||||
private long pages;
|
||||
|
||||
|
||||
public PageVo() {
|
||||
}
|
||||
|
||||
public PageVo(int page, int size) {
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public PageVo(int page, int size, String sort, String order) {
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
this.sort = sort;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
|
||||
}
|
22
src/main/java/com/example/hotel/vo/SearchVo.java
Executable file
22
src/main/java/com/example/hotel/vo/SearchVo.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package com.example.hotel.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author example
|
||||
*/
|
||||
@Data
|
||||
public class SearchVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 起始日期
|
||||
*/
|
||||
private String startDate;
|
||||
|
||||
/**
|
||||
* 结束日期
|
||||
*/
|
||||
private String endDate;
|
||||
}
|
81
src/main/resources/application.yaml
Executable file
81
src/main/resources/application.yaml
Executable file
@@ -0,0 +1,81 @@
|
||||
server:
|
||||
port: 8080
|
||||
forward-headers-strategy: true
|
||||
undertow:
|
||||
io-threads: 2
|
||||
worker-threads: 36
|
||||
buffer-size: 1024
|
||||
directBuffers: true
|
||||
servlet:
|
||||
session:
|
||||
timeout: 86400
|
||||
|
||||
spring:
|
||||
transaction:
|
||||
rollback-on-commit-failure: true
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
#MySql配置
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/hotux?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&allowMultiQueries=true
|
||||
username: root
|
||||
password: 123456
|
||||
thymeleaf:
|
||||
mode: HTML5
|
||||
cache: false
|
||||
prefix: classpath:/templates/
|
||||
encoding: UTF-8
|
||||
suffix: .html
|
||||
check-template-location: false
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 2000MB
|
||||
max-request-size: 2000MB
|
||||
devtools:
|
||||
restart:
|
||||
enabled: true
|
||||
additional-paths: src/main/java
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:/mapper/**Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: com.example.sens.entity
|
||||
global-config:
|
||||
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
|
||||
id-type: 0
|
||||
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
|
||||
field-strategy: 2
|
||||
#驼峰下划线转换
|
||||
db-column-underline: true
|
||||
#刷新mapper 调试神器
|
||||
refresh-mapper: true
|
||||
#逻辑删除配置(下面3个配置)
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: true
|
||||
|
||||
logging:
|
||||
file: ./logs/log.log
|
||||
level:
|
||||
org:
|
||||
springframework:
|
||||
boot:
|
||||
autoconfigure: error
|
||||
# web:
|
||||
# trace
|
||||
|
||||
application:
|
||||
formatted-version: 1.0.0
|
||||
|
||||
shiro:
|
||||
userNativeSessionManager: true
|
||||
|
||||
mail:
|
||||
smtp:
|
||||
host: smtp.qq.com
|
||||
username: 847064370@qq.com
|
||||
password: vtvhcjsacnuubdaj
|
||||
from:
|
||||
name: Hotux
|
23
src/main/resources/mapper/CategoryMapper.xml
Normal file
23
src/main/resources/mapper/CategoryMapper.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.hotel.mapper.CategoryMapper">
|
||||
|
||||
<delete id="deleteByUserId">
|
||||
DELETE
|
||||
FROM
|
||||
category
|
||||
WHERE
|
||||
user_id = #{value}
|
||||
</delete>
|
||||
|
||||
<select id="selectChildCateIds" resultType="java.lang.Long">
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
category
|
||||
WHERE
|
||||
path_trace LIKE CONCAT('%', #{pathTrace}, '%')
|
||||
AND del_flag = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
54
src/main/resources/mapper/OrderMapper.xml
Normal file
54
src/main/resources/mapper/OrderMapper.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.hotel.mapper.OrderMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.example.hotel.entity.Order">
|
||||
<id column="id" property="id"></id>
|
||||
<result column="post_id" property="postId"></result>
|
||||
<result column="user_id" property="userId"></result>
|
||||
<result column="quantity" property="quantity"></result>
|
||||
<result column="status" property="status"></result>
|
||||
<result column="start_date" property="startDate"></result>
|
||||
<result column="name" property="name"></result>
|
||||
<result column="phone" property="phone"></result>
|
||||
<result column="id_card" property="idCard"></result>
|
||||
<result column="price" property="price"></result>
|
||||
<result column="total_price" property="totalPrice"></result>
|
||||
<result column="post_title" property="postTitle"></result>
|
||||
<result column="post_number" property="postNumber"></result>
|
||||
<result column="create_time" property="createTime"></result>
|
||||
</resultMap>
|
||||
|
||||
<select id="findAll" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
id, post_id, user_id, quantity, status, start_date, name, phone, id_card, price, total_price, post_title, post_number, create_time
|
||||
FROM
|
||||
t_order
|
||||
WHERE
|
||||
<if test="startDate != null">
|
||||
create_time >= STR_TO_DATE( #{startDate}, "%Y-%m-%d" ) AND
|
||||
</if>
|
||||
<if test="endDate != null">
|
||||
create_time <= STR_TO_DATE( #{endDate}, "%Y-%m-%d" )+1 AND
|
||||
</if>
|
||||
del_flag = 0
|
||||
</select>
|
||||
|
||||
<select id="getTotalPriceSum" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
sum(total_price)
|
||||
FROM
|
||||
t_order
|
||||
<where>
|
||||
<if test="startDate != null">
|
||||
create_time >= STR_TO_DATE( #{startDate}, "%Y-%m-%d" ) AND
|
||||
</if>
|
||||
<if test="endDate != null">
|
||||
create_time <= STR_TO_DATE( #{endDate}, "%Y-%m-%d" )+1 AND
|
||||
</if>
|
||||
del_flag = 0
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
142
src/main/resources/mapper/PermissionMapper.xml
Normal file
142
src/main/resources/mapper/PermissionMapper.xml
Normal file
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.hotel.mapper.PermissionMapper">
|
||||
|
||||
<select id="findByRoleId" resultType="com.example.hotel.entity.Permission">
|
||||
SELECT
|
||||
DISTINCT t.id,
|
||||
t.`name`,
|
||||
t.pid,
|
||||
t.resource_type,
|
||||
t.url,
|
||||
t.icon,
|
||||
t.sort
|
||||
FROM
|
||||
permission t,
|
||||
role_permission_ref r
|
||||
WHERE
|
||||
r.role_id = #{value} AND
|
||||
t.id = r.permission_id
|
||||
AND t.del_flag = 0
|
||||
AND r.del_flag = 0
|
||||
ORDER BY t.sort ASC
|
||||
</select>
|
||||
|
||||
<select id="findPermissionByUserId" resultType="com.example.hotel.entity.Permission">
|
||||
SELECT
|
||||
DISTINCT p.id,
|
||||
p.`name`,
|
||||
p.pid,
|
||||
p.resource_type,
|
||||
p.url,
|
||||
p.icon,
|
||||
p.sort
|
||||
FROM
|
||||
user u,
|
||||
role r,
|
||||
user_role_ref ur,
|
||||
permission p,
|
||||
role_permission_ref rp
|
||||
WHERE
|
||||
u.id = #{userId}
|
||||
AND ur.user_id = u.id
|
||||
AND ur.role_id = r.id
|
||||
AND rp.permission_id = p.id
|
||||
AND rp.role_id = r.id
|
||||
AND u.del_flag = 0
|
||||
AND r.del_flag = 0
|
||||
AND ur.del_flag = 0
|
||||
AND p.del_flag = 0
|
||||
AND rp.del_flag = 0
|
||||
ORDER BY p.sort ASC
|
||||
</select>
|
||||
|
||||
|
||||
<select id="findPermissionByUserIdAndResourceType" resultType="com.example.hotel.entity.Permission">
|
||||
SELECT
|
||||
DISTINCT p.id,
|
||||
p.`name`,
|
||||
p.pid,
|
||||
p.resource_type,
|
||||
p.url,
|
||||
p.icon,
|
||||
p.sort
|
||||
FROM
|
||||
user u,
|
||||
role r,
|
||||
user_role_ref ur,
|
||||
permission p,
|
||||
role_permission_ref rp
|
||||
WHERE
|
||||
u.id = #{userId}
|
||||
AND ur.user_id = u.id
|
||||
AND ur.role_id = r.id
|
||||
AND rp.permission_id = p.id
|
||||
AND rp.role_id = r.id
|
||||
AND p.resource_type = #{resourceType}
|
||||
AND u.del_flag = 0
|
||||
AND r.del_flag = 0
|
||||
AND ur.del_flag = 0
|
||||
AND p.del_flag = 0
|
||||
AND rp.del_flag = 0
|
||||
ORDER BY p.sort ASC
|
||||
</select>
|
||||
|
||||
<select id="findPermissionByResourceType" resultType="com.example.hotel.entity.Permission">
|
||||
SELECT
|
||||
DISTINCT p.id,
|
||||
p.`name`,
|
||||
p.pid,
|
||||
p.resource_type,
|
||||
p.url,
|
||||
p.icon,
|
||||
p.sort
|
||||
FROM
|
||||
permission p
|
||||
<where>
|
||||
|
||||
<if test="resourceType != null">
|
||||
p.resource_type = #{resourceType} AND
|
||||
</if>
|
||||
p.del_flag = 0
|
||||
</where>
|
||||
ORDER BY p.sort ASC
|
||||
</select>
|
||||
|
||||
<select id="findPermissionByRoleId" resultType="com.example.hotel.entity.Permission">
|
||||
SELECT
|
||||
p.id,
|
||||
p.pid,
|
||||
p.name,
|
||||
p.sort,
|
||||
p.resource_type
|
||||
FROM
|
||||
permission p,
|
||||
role_permission_ref r
|
||||
WHERE
|
||||
p.id = r.permission_id
|
||||
AND p.del_flag = 0
|
||||
AND r.del_flag = 0
|
||||
AND r.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
<select id="countChildPermission" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
permission
|
||||
WHERE
|
||||
pid = #{id}
|
||||
AND del_flag = 0
|
||||
</select>
|
||||
|
||||
<select id="findByUrl" resultType="com.example.hotel.entity.Permission">
|
||||
SELECT
|
||||
id, name, pid, resource_type, url
|
||||
FROM
|
||||
permission
|
||||
WHERE
|
||||
url = #{url} AND del_flag = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
64
src/main/resources/mapper/PostMapper.xml
Normal file
64
src/main/resources/mapper/PostMapper.xml
Normal file
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.hotel.mapper.PostMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.example.hotel.entity.Post">
|
||||
<id column="id" property="id"></id>
|
||||
<result column="post_title" property="postTitle"></result>
|
||||
<result column="post_summary" property="postSummary"></result>
|
||||
<result column="post_thumbnail" property="postThumbnail"></result>
|
||||
<result column="create_time" property="createTime"></result>
|
||||
<result column="post_status" property="postStatus"></result>
|
||||
<result column="price" property="price"></result>
|
||||
<result column="number" property="number"></result>
|
||||
<result column="img_url" property="imgUrl"></result>
|
||||
<association property="category" javaType="com.example.hotel.entity.Category">
|
||||
<id property="id" column="cate_id"/>
|
||||
<result property="cateName" column="cate_name"/>
|
||||
<result property="cateDesc" column="cate_desc"/>
|
||||
<result property="cateSort" column="cate_sort"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
<select id="findPostByCondition" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
p.id,
|
||||
p.post_title,
|
||||
p.post_summary,
|
||||
p.post_thumbnail,
|
||||
p.create_time,
|
||||
p.post_status,
|
||||
p.price,
|
||||
p.number,
|
||||
p.img_url,
|
||||
c.id cate_id,
|
||||
c.cate_name,
|
||||
c.cate_sort
|
||||
FROM
|
||||
post p,
|
||||
category c
|
||||
<where>
|
||||
p.post_status = 0 AND
|
||||
p.cate_id = c.id AND
|
||||
<if test="condition.cateId != null and condition.cateId != 0">
|
||||
c.id = #{condition.cateId} AND
|
||||
</if>
|
||||
<if test="condition.dateList != null and condition.dateList.size() > 0">
|
||||
p.id NOT IN ( SELECT post_id FROM record WHERE record_date IN (
|
||||
<foreach collection="condition.dateList" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
)
|
||||
AND del_flag = 0 ) AND
|
||||
</if>
|
||||
p.del_flag = 0 AND
|
||||
c.del_flag = 0
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="countPostByCateId" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM post
|
||||
WHERE cate_id = #{value} AND del_flag = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user