首页>代码>基于ssm的房屋租赁系统>/house/src/main/java/controller/ApplyController.java
package controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import pojo.*;
import service.ApplyService;
import service.HouselistService;
import service.UserlistService;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ApplyController {
    @Autowired
    private UserlistService userlistService;
    @Autowired
    private HouselistService houselistService;
    @Autowired
    private ApplyService applyService;

    //申请看房
    @RequestMapping("/applycheckuserlist")
    public String applycheckuserlist(HttpSession httpSession, Model model, Integer id) {
        User user1 = (User) httpSession.getAttribute("user");
        Integer user_id = user1.getId();
        Userlist list = userlistService.findhasuserlist(user_id);
        if (list == null) {
            model.addAttribute("error", "applycheck");
            return "redirect:houselist.action";
        } else {
            Houselist houselist = houselistService.findid(id);
            houselist.setStatus("已被申请");
            houselistService.updatehousestatus(houselist);
            Integer userlist_id = list.getId();
            Apply apply = new Apply();
            apply.setHouse_id(houselist.getHouseid());
            apply.setAddress(houselist.getAddress());
            apply.setPrice(houselist.getPrice());
            apply.setArea(houselist.getArea());
            apply.setStatus("申请中");
            apply.setUserlist_id(userlist_id);
            applyService.insertapply(apply);
            model.addAttribute("error", "applysuccess");
            return "redirect:houselist.action";
        }

    }

    //管理员查看申请看房列表
    @RequestMapping("/findapplylist")
    public String findapplylist(Model model, @RequestParam(required = false, defaultValue = "1") Integer page,
                                @RequestParam(required = false, defaultValue = "2") Integer pageSize) throws Exception {
        PageHelper.startPage(page, pageSize);
        List<Apply> applylist = applyService.findapplylist();
        PageInfo<Apply> p = new PageInfo<Apply>(applylist);
        model.addAttribute("applylist", applylist);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "applylist.jsp");
        return "/jsp/admin/main1";
    }

    @RequestMapping("/applychangehousestatus")
    public String applychangehousestatus(HttpSession httpSession, Model model, String house_id) throws Exception {
        User user1 = (User) httpSession.getAttribute("user");
        Integer user_id = user1.getId();
        Userlist userlist = userlistService.findhasuserlist(user_id);
        Houselist houselist = houselistService.findhouseid(house_id);
        houselist.setStatus("已租赁");
        houselistService.updatehousestatus(houselist);
        Zulist zulist = new Zulist();
        zulist.setHouse_id(house_id);
        zulist.setPrice(houselist.getPrice());
        zulist.setAddress(houselist.getAddress());

        return "";
    }

    //管理员拒绝看房申请
    @RequestMapping("/refuseapply")
    public String refuseapply(String house_id, Model model) {
        Houselist houselist = new Houselist();
        houselist.setHouseid(house_id);
        houselist.setStatus("未租赁");
        applyService.refuseapply(houselist);

        return "redirect:findapplylist.action";
    }

    //租客查看自己的 看房申请
    @RequestMapping("/getmyapply")
    public String getmyapply(Model model, HttpSession httpSession, @RequestParam(required = false, defaultValue = "1") Integer page,
                             @RequestParam(required = false, defaultValue = "2") Integer pageSize) {
        User user1 = (User) httpSession.getAttribute("user");
        Userlist userlist = userlistService.findhasuserlist(user1.getId());
        if (userlist == null) {
            return "/jsp/zuke/404";
        }
        PageHelper.startPage(page, pageSize);
        List<Userlist> list = userlistService.getmyapply(userlist.getId());
        PageInfo<Userlist> p = new PageInfo<Userlist>(list);
        model.addAttribute("userlist", list);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "myapply.jsp");
        return "/jsp/zuke/main";
    }


}
最近下载更多
胡棋俊  LV4 11月17日
lisansiwu  LV2 11月8日
罗清晨  LV13 11月1日
bridge_44  LV2 10月28日
yayacui  LV2 10月28日
yfb790910  LV3 9月22日
Peny_ZH  LV5 9月19日
zolscy  LV12 9月11日
lyws1986  LV17 7月14日
799743530  LV11 7月7日
最近浏览更多
驱蚊器我 11月18日
暂无贡献等级
citybird  LV4 11月17日
学熊涅槃  LV2 11月15日
oceanchen  LV14 11月13日
lisansiwu  LV2 11月8日
罗清晨  LV13 11月1日
林kkkkkk  LV6 10月31日
416696772 10月31日
暂无贡献等级
bridge_44  LV2 10月28日
shunlun8855  LV1 10月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友