瀏覽代碼

小修改

CHENYIZONG 6 年之前
父節點
當前提交
d20ba9e4dc

+ 9 - 0
src/main/java/com/example/hotel/bl/admin/AdminService.java

@@ -12,8 +12,17 @@ import java.util.List;
  */
 public interface AdminService {
 
+    /**
+     * 添加酒店管理人员账号
+     * @param userForm
+     * @return
+     */
     ResponseVO addManager(UserForm userForm);
 
+    /**
+     * 获得所有酒店管理人员信息
+     * @return
+     */
     List<User> getAllManagers();
 
 

+ 14 - 0
src/main/java/com/example/hotel/bl/order/OrderService.java

@@ -12,10 +12,24 @@ import java.util.List;
  */
 public interface OrderService {
 
+    /**
+     * 预订酒店
+     * @param orderVO
+     * @return
+     */
     ResponseVO addOrder(OrderVO orderVO);
 
+    /**
+     * 获得所有订单信息
+     * @return
+     */
     List<Order> getAllOrders();
 
+    /**
+     * 获得指定用户的所有订单信息
+     * @param userid
+     * @return
+     */
     List<Order> getUserOrders(int userid);
 
 }

+ 13 - 0
src/main/java/com/example/hotel/bl/user/AccountService.java

@@ -23,8 +23,21 @@ public interface AccountService {
      */
     User login(UserForm userForm);
 
+    /**
+     * 获取用户个人信息
+     * @param id
+     * @return
+     */
     User getUserInfo(int id);
 
+    /**
+     * 更新用户个人信息
+     * @param id
+     * @param password
+     * @param username
+     * @param phonenumber
+     * @return
+     */
     ResponseVO updateUserInfo(int id, String password,String username,String phonenumber);
 
 

+ 0 - 61
src/main/java/com/example/hotel/config/WebConfiguration.java

@@ -1,61 +0,0 @@
-//package com.example.hotel.config;
-//
-///**
-// * @Author: chenyizong
-// * @Date: 2020-03-03
-// */
-//import com.example.hotel.interceptor.TokenInterceptor;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
-//import org.springframework.web.servlet.config.annotation.*;
-//
-//import java.util.ArrayList;
-//import java.util.List;
-//import java.util.concurrent.Executors;
-//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-//
-//
-///**
-// * 跨域请求支持/token拦截
-// * tip:只能写在一个配置类里
-// */
-//@Configuration
-//public class WebConfiguration implements WebMvcConfigurer {
-//
-//    private TokenInterceptor tokenInterceptor;
-//
-//    //构造方法
-//    public WebConfiguration(TokenInterceptor tokenInterceptor){
-//        this.tokenInterceptor = tokenInterceptor;
-//    }
-//
-//    @Override
-//    public void addCorsMappings(CorsRegistry registry) {
-//        registry.addMapping("/**")
-//                .allowCredentials(true)
-//                .allowedHeaders("*")
-//                .allowedMethods("*");
-//                //.allowedOrigins("*");
-//    }
-//
-//    @Override
-//    public void configureAsyncSupport(AsyncSupportConfigurer configurer){
-//        configurer.setTaskExecutor(new ConcurrentTaskExecutor(Executors.newFixedThreadPool(3)));
-//        configurer.setDefaultTimeout(30000);
-//    }
-//
-//    @Override
-//    public void addInterceptors(InterceptorRegistry registry){
-//        List<String> excludePath = new ArrayList<>();
-//        //排除拦截,除了注册登录(此时还没token),其他都拦截
-//        excludePath.add("/api/user/register");
-//        excludePath.add("/api/user/login");
-//        excludePath.add("/static/**");
-//        excludePath.add("/assets/**");
-//
-//        registry.addInterceptor(tokenInterceptor)
-//                .addPathPatterns("/**")
-//                .excludePathPatterns(excludePath);
-//        WebMvcConfigurer.super.addInterceptors(registry);
-//    }
-//}

+ 0 - 6
src/main/java/com/example/hotel/controller/user/AccountController.java

@@ -2,7 +2,6 @@ package com.example.hotel.controller.user;
 
 import com.example.hotel.blImpl.user.AccountServiceImpl;
 import com.example.hotel.po.User;
-import com.example.hotel.util.TokenUtil;
 import com.example.hotel.vo.UserForm;
 import com.example.hotel.vo.ResponseVO;
 import com.example.hotel.vo.UserInfoVO;
@@ -25,7 +24,6 @@ public class AccountController {
         if (user == null) {
             return ResponseVO.buildFailure(ACCOUNT_INFO_ERROR);
         }
-       // String token = TokenUtil.sign(user);
         return ResponseVO.buildSuccess(user);
 
     }
@@ -38,8 +36,6 @@ public class AccountController {
 
     @GetMapping("/{id}/getUserInfo")
     public ResponseVO getUserInfo(@PathVariable int id) {
-//        String token = httpServletRequest.getHeader("Authorization");
-//        String email = TokenUtil.getEmail(token);
         User user = accountService.getUserInfo(id);
         if(user==null){
             return ResponseVO.buildFailure(ACCOUNT_INFO_ERROR);
@@ -49,8 +45,6 @@ public class AccountController {
 
     @PostMapping("/{id}/userInfo/update")
     public ResponseVO updateInfo(@RequestBody UserInfoVO userInfoVO,@PathVariable int id){
-        //String token = httpServletRequest.getHeader("token");
-       // String email = TokenUtil.getEmail(token);
         return accountService.updateUserInfo(id,userInfoVO.getPassword(),userInfoVO.getUserName(),userInfoVO.getPhoneNumber());
 
     }

+ 0 - 48
src/main/java/com/example/hotel/interceptor/TokenInterceptor.java

@@ -1,48 +0,0 @@
-//package com.example.hotel.interceptor;
-//
-///**
-// * @Author: chenyizong
-// * @Date: 2020-03-03
-// */
-//import com.alibaba.fastjson.JSONObject;
-//import com.example.hotel.util.TokenUtil;
-//import org.springframework.stereotype.Component;
-//import org.springframework.web.servlet.HandlerInterceptor;
-//
-//import javax.servlet.http.HttpServletRequest;
-//import javax.servlet.http.HttpServletResponse;
-//
-//@Component
-//public class TokenInterceptor implements HandlerInterceptor {
-//
-//    @Override
-//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler)throws Exception{
-//        if(request.getMethod().equals("OPTIONS")){
-//            response.setStatus(HttpServletResponse.SC_OK);
-//            return true;
-//        }
-//        response.setCharacterEncoding("utf-8");
-//        String token = request.getHeader("Authorization");
-//        if(token != null){
-//            boolean result = TokenUtil.verify(token);
-//            if(result){
-//                System.out.println("通过拦截器");
-//                return true;
-//            }
-//        }
-//        response.setCharacterEncoding("UTF-8");
-//        response.setContentType("application/json; charset=utf-8");
-//        try{
-//            JSONObject json = new JSONObject();
-//            json.put("msg","token verify fail");
-//            json.put("code","50000");
-//            response.getWriter().append(json.toJSONString());
-//            System.out.println("认证失败,未通过拦截器");
-//        }catch (Exception e){
-//            e.printStackTrace();
-//            response.sendError(500);
-//            return false;
-//        }
-//        return false;
-//    }
-//}

+ 0 - 74
src/main/java/com/example/hotel/util/TokenUtil.java

@@ -1,74 +0,0 @@
-package com.example.hotel.util;
-
-/**
- * @Author: chenyizong
- * @Date: 2020-03-03
- */
-
-import com.auth0.jwt.JWT;
-import com.auth0.jwt.JWTVerifier;
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTDecodeException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.example.hotel.po.User;
-
-import java.util.Date;
-
-public class TokenUtil {
-
-    private static final long EXPIRE_TIME= 10*60*60*1000;
-    private static final String TOKEN_SECRET="txdy";  //密钥盐
-
-    /**
-     * 签名生成
-     * @param user
-     * @return
-     */
-    public static String sign(User user){
-        String token = null;
-        try {
-            Date expiresAt = new Date(System.currentTimeMillis() + EXPIRE_TIME);
-            token = JWT.create()
-                    .withIssuer("auth0")
-                    .withClaim("email", user.getEmail())
-                    .withExpiresAt(expiresAt)
-                    // 使用了HMAC256加密算法。
-                    .sign(Algorithm.HMAC256(TOKEN_SECRET));
-        } catch (Exception e){
-            e.printStackTrace();
-        }
-        return token;
-    }
-
-    /**
-     * 签名验证
-     * @param token
-     * @return
-     */
-    public static boolean verify(String token){
-        try {
-            JWTVerifier verifier = JWT.require(Algorithm.HMAC256(TOKEN_SECRET)).withIssuer("auth0").build();
-            DecodedJWT jwt = verifier.verify(token);
-            System.out.println("认证通过:");
-            System.out.println("email: " + jwt.getClaim("email").asString());
-            System.out.println("过期时间:      " + jwt.getExpiresAt());
-            return true;
-        } catch (Exception e){
-            return false;
-        }
-    }
-
-    /**
-     * 获得token中的信息无需secret解密也能获得
-     *
-     * @return token中包含的用户名
-     */
-    public static String getEmail(String token) {
-        try {
-            DecodedJWT jwt = JWT.decode(token);
-            return jwt.getClaim("email").asString();
-        } catch (JWTDecodeException e) {
-            return null;
-        }
-    }
-}

+ 1 - 2
src/main/resources/dataImpl/hotel/HotelMapper.xml

@@ -3,8 +3,7 @@
 <mapper namespace="com.example.hotel.data.hotel.HotelMapper">
     <insert id="insertHotel" parameterType="com.example.hotel.po.Hotel"
     useGeneratedKeys="true" keyProperty="id">
-        insert into Hotel(address,bizRegion,hotelDescription,hotelStar,hotelName,phoneNum,
-        rate,manager_id)
+        insert into Hotel(address,bizRegion,hotelDescription,hotelStar,hotelName,phoneNum,rate,manager_id)
         values (#{address},#{bizRegion},#{description},#{hotelStar},#{hotelName},#{phoneNum},#{rate},#{managerId})
     </insert>