首页>代码>Spring mvc+jdbc+jstl分页,ajax开发的java web酒店管理系统,适合入门>/新建文件夹 (2)/jiudianguanli/src/com/bdnq/controller/FangJianController.java
package com.bdnq.controller; 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; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSON; import com.bdnq.dao.CaiWuDao; import com.bdnq.dao.FangJianDao; import com.bdnq.dao.RuZhuDao; import com.bdnq.dao.UserDao; import com.bdnq.dao.impl.CaiWuDaoImpl; import com.bdnq.dao.impl.FangJianDaoImpl; import com.bdnq.dao.impl.RuZhuDaoImpl; import com.bdnq.dao.impl.UserDaoImpl; import com.bdnq.entity.CaiWu; import com.bdnq.entity.FangJian; import com.bdnq.entity.RuZhu; import com.bdnq.entity.User; import com.bdnq.service.FangJianService; @Controller @RequestMapping("/fangjian") public class FangJianController { private static String uid = UserController.uid; @Autowired private FangJianService fangJianService; private UserDao userDao = new UserDaoImpl(); private RuZhuDao ruZhuDao = new RuZhuDaoImpl(); private CaiWuDao cwDao = new CaiWuDaoImpl(); private FangJianDao fjDao = new FangJianDaoImpl(); //查询传过来的身份证顾客id private static String getUserById = null; //经理展示房间页面 @RequestMapping("/getAllFangJian") public String getAllFangJian(HttpServletRequest request){ List<FangJian> list = fangJianService.getAllFangJian(); request.setAttribute("FangJian", list); return "getAllFangJian"; } //前台人员展示房间页面 @RequestMapping("/getAllfj") public String getAllfj(HttpServletRequest request){ List<FangJian> list = fangJianService.getAllFangJian(); request.setAttribute("fj", list); if (getUserById!=null) { request.setAttribute("getUserById", getUserById); }else{ request.setAttribute("getUserById", ""); } return "fangjianguanli"; } //预定功能 @RequestMapping("/yuding") @ResponseBody public String yuding(String gukeid,double jiage,String zhifu,String fangjianid,String tianshu,Date ruzhushijian){ User user = new User(); user = userDao.getUserById(gukeid); System.out.println("传值信息顾客id"+user.getUserid()+"顾客id"+gukeid+"价格"+jiage+"支付方式"+zhifu+"房间id"+fangjianid+"预定天数"+tianshu+"入住时间"+ruzhushijian); if (user.getUserid().equals("")) { return JSON.toJSONString("请先添加此顾客信息!!!"); }else{ Date t = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date date = null; //入住时间 Date ruzhusj = null; Date time =new Date(ruzhushijian.toString()); System.out.println(ruzhushijian.toString()); String timeFormat = df.format(time); System.out.println(timeFormat+"ssss"); try { date = df.parse(df.format(t)); ruzhusj = df.parse(timeFormat); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } //房间到期日期 String ruzusj = null; try { ruzusj = FangJianController.testname(timeFormat,tianshu); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Date shijian = null;; try { shijian = df.parse(ruzusj); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //到期时间 System.out.println("预定成功!!!"); //顾客入住信息 RuZhu rz =new RuZhu(); rz.setFangjianbianhao(String.valueOf((Integer.valueOf(fangjianid)-99))); rz.setRuzhuriqi(date); rz.setUsername(user.getUsername()); rz.setShenfenzhang(user.getShenfenzheng()); rz.setFuwuyuangongbianhao(UserController.uid); rz.setDaoqishijian(shijian); if (user.getDianhua()!=null) { rz.setLianxifangshi(user.getDianhua()); }else if(user.getDianhua()!=null||user.getWeixin()!=null){ rz.setLianxifangshi(user.getDianhua()+user.getWeixin()); }else if(user.getDianhua()!=null||user.getWeixin()!=null||user.getQQ()!=null){ rz.setLianxifangshi(user.getDianhua()+user.getWeixin()+user.getQQ()); }else{ System.out.println("联系方式使用默认值!!!"); rz.setLianxifangshi("默认没有联系方式"); } rz.setZhifufangshi(zhifu); rz.setJinge(jiage*Integer.valueOf(tianshu)); ruZhuDao.insertRuZhu(rz); //财务报表 CaiWu cw = new CaiWu(); cw.setShourulaiyuan("顾客id为"+gukeid+"入住房间id为:"+(Integer.valueOf(fangjianid)-99)+"房间"); System.out.println(cw.getShourulaiyuan()); cw.setZhichuquxiang(""); cw.setShijian(date); cw.setJinge(jiage* Integer.valueOf(tianshu)); cwDao.insertCaiWu(cw); FangJian fj = new FangJian(); fj.setRuzhuqingkang("入住"); fj.setYonghuid(Integer.valueOf(gukeid)); fj.setShifouyuding("是"); if (ruzhushijian==null) { fj.setRuzhushijian(date); }else{ fj.setRuzhushijian(ruzhusj); } fj.setDaoqishijian(shijian); //已经在房间dao接口内部转换了,这里不用-99 fj.setFangjianid(Integer.valueOf(fangjianid)); int rows = fjDao.updata(fj); if (rows>0) { System.out.println("房间状态更新成功!!!"); } return JSON.toJSONString("顾客id为"+gukeid+"预定成功!!!"); } } //入住日期+预定天数==到期房间日期 public static String testname(String riqi,String yudingtianshu) throws Exception { Date d = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String s= riqi; Date date = format.parse(s); System.out.println("现在的日期是:" + riqi); s = riqi; Calendar ca = Calendar.getInstance(); ca.setTime(date); ca.add(Calendar.DATE, Integer.valueOf(yudingtianshu));// num为增加的天数,可以改变的 d = ca.getTime(); String enddate = format.format(d); System.out.println("增加天数以后的日期:" + enddate); return enddate; } //退房服务 @RequestMapping("/tuiFang") @ResponseBody public String tuiFang(String fangjianid){ FangJian fj = new FangJian(); System.out.println(fangjianid); fj.setQinglizhuangtai(1); fj.setFangjianid(Integer.valueOf(fangjianid)); int rows = fjDao.tuifang(fj); if (rows>0) { System.out.println("退房成功!!!"); return "退房成功!!!"; } else { System.out.println("退房失败!!!"); return "退房失败!!!"; } } //增加房间 @RequestMapping("/insertFangJian") public String insertFangJian(HttpServletRequest request){ FangJian fj = new FangJian(); fj.setBianhao(request.getParameter("fangjianbianhao")); fj.setFangjiantype(request.getParameter("fangjiantype")); fj.setJiage(Integer.valueOf(request.getParameter("jiage"))); int rows = fjDao.insertFangJian(fj); if (rows>0) { System.out.println("增加成功!!!"); } else { System.out.println("增加失败!!!"); } return "redirect:getAllfj"; } @RequestMapping("/getByFangJianId") public String getByFangJianId(HttpServletRequest request){ String fangjianid = request.getParameter("fangjianid"); FangJian fj = fjDao.getByFangJianId(fangjianid); System.out.println(fj.getBianhao()); request.setAttribute("fj", fj); System.out.println(fj.getRuzhuqingkang()); System.out.println(fj.getFangjiantype()); return "updateFangJian"; } //修改房间信息代码 @RequestMapping("/updateFangJian") public String updateFangJian(HttpServletRequest request){ FangJian fj = new FangJian(); fj.setFangjianid(Integer.valueOf(request.getParameter("fangjianid"))); fj.setBianhao(request.getParameter("fangjianbianhao")); fj.setRuzhuqingkang(request.getParameter("ruzhuqingkuang")); fj.setQinglizhuangtai(Integer.valueOf(request.getParameter("qinglizhuangtai"))); fj.setFangjiantype(request.getParameter("fangjiantype")); fj.setShifouyuding(request.getParameter("shifouyuding")); if (request.getParameter("daoqishijian")!=null) { //转换时间格式 DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date dqsj = null; Date rzsj = null; String d = request.getParameter("daoqishijian"); String dd = request.getParameter("ruzhushijian"); try { dqsj = format.parse(d); // Thu Jan 18 00:00:00 CST 2007 rzsj = format.parse(dd); // Thu Jan 18 00:00:00 CST 2007 } catch (ParseException e) { e.printStackTrace(); } fj.setYonghuid(Integer.valueOf(request.getParameter("yonghuid"))); fj.setDaoqishijian(dqsj); fj.setRuzhushijian(rzsj); int rows = fjDao.updateFangJian(fj); if (rows>0) { System.out.println("修改成功"); } else { System.out.println("修改失败"); } } if (request.getParameter("daoqishijian")==null) { int rows = fjDao.updatef(fj); if (rows>0) { System.out.println("修改成功"); } else { System.out.println("修改失败"); } } //执行修改处理结果 return "redirect:getAllfj"; } //换房服务 @RequestMapping("/huanfang") public String huanfang(HttpServletRequest request){ request.setAttribute("fangjianid", request.getParameter("fangjianid")); List<FangJian> listfj = new ArrayList<FangJian>(); listfj = fjDao.getAllFangJian(); request.setAttribute("fangjian", listfj); return "huanfang"; } //修改换房 @RequestMapping("/tijiaohuanfang") public String tijiaohuanfang(HttpServletRequest request){ String fangjianid = request.getParameter("fangjianid"); String huanfangid = request.getParameter("huanfang"); String shifouqingli = request.getParameter("shifouqingli"); //查询房间编号这里 FangJian gg = fjDao.getByFangJianId(huanfangid); //原房间信息 FangJian fj = fjDao.getByFangJianId(fangjianid); fj.setFangjianid(Integer.valueOf(huanfangid)); fj.setBianhao(gg.getBianhao()); int rows = fjDao.updateFangJian(fj); if (rows>0) { System.out.println("修改新房间成功!!!"); } else { System.out.println("修改失败!!!"); } FangJian x = new FangJian(); x.setQinglizhuangtai(Integer.valueOf(shifouqingli)); x.setFangjianid(Integer.valueOf(fangjianid)); int xx = fjDao.tuifang(x); if (xx>0) { System.out.println("清空原房间成功!!!"); } else { System.out.println("清空失败!!!"); } return "redirect:getAllfj"; } //根据用户id查询身份证并且反馈前台 @RequestMapping("/getUserById") public String getUserById(HttpServletRequest request){ String userid = request.getParameter("gkbianhao"); String shenfenzheng = userDao.getUserByShenFenZheng(userid); String x = shenfenzheng; getUserById = shenfenzheng; System.out.println(x+"sssssss"+userid); return "redirect:getAllfj"; } }
最近下载更多
颜菜菜 LV2
2023年12月23日
214109 LV2
2022年12月9日
微信网友_6248713511227392 LV11
2022年12月5日
最代码-宋家辉 LV61
2022年6月23日
user123qyb LV1
2022年5月17日
xk16675552250 LV33
2022年3月31日
程序员阿莱 LV2
2021年11月23日
小火火 LV7
2021年10月4日
famloliy LV6
2021年8月23日
康日澜 LV9
2021年6月26日
最近浏览更多
xiao小果 LV13
8月27日
TY0165 LV20
6月24日
1827129306e LV1
5月27日
pokerf LV5
4月26日
微信网友_6906962132258816 LV7
4月15日
yeanan LV1
3月28日
heshao LV2
1月11日
颜菜菜 LV2
2023年12月23日
yolo_light LV1
2023年12月21日
wdw2444156008
2023年10月31日
暂无贡献等级