package com.hrs.controller.landlord;

import com.hrs.dao.OrderDao;
import com.hrs.dao.impl.OrderDaoImpl;
import com.hrs.model.entity.Order;
import com.hrs.model.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**   
* Copyright: Copyright (c) 2026 chinasofti
* 
* @ClassName: OrderManageController.java
* @Description: 房东订单管理控制器
*
* @version: v1.0.0
* @author: 李鑫
* @date: 2026年4月13日 上午9:01:28 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* 2026年4月13日     李鑫           v1.0.0               新建文件
*/
@WebServlet("/landlord/order/list")
public class OrderManageController extends HttpServlet {
    
    private OrderDao orderDao = new OrderDaoImpl();
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        
        HttpSession session = request.getSession(false);
        if (session == null) {
            response.sendRedirect(request.getContextPath() + "/user/login");
            return;
        }
        
        User loginUser = (User) session.getAttribute("loginUser");
        if (loginUser == null || !"1".equals(loginUser.getRoleType())) {
            response.sendRedirect(request.getContextPath() + "/user/login");
            return;
        }
        
        List<Order> orderList = orderDao.findByLandlordId(loginUser.getId());
        
        request.setAttribute("orderList", orderList);
        request.setAttribute("totalCount", orderList.size());
        request.setAttribute("loginUser", loginUser);
        
        request.getRequestDispatcher("/jsp/landlord/order_list.jsp").forward(request, response);
    }
}