/* * Distributable under LGPL v3 license. * See terms of license at https://github.com/Yunfeng/schotel/blob/master/LICENSE */ package cn.buk.qms.action; import cn.buk.api.service.CtripHotelService; import cn.buk.hotel.dto.*; import cn.buk.hotel.entity.ContactInfo; import cn.buk.hotel.entity.HotelInfo; import cn.buk.hotel.entity.HotelOrder; import cn.buk.hotel.entity.HotelOrderGuest; import cn.buk.hotel.service.HotelService; import cn.buk.util.DateUtil; import cn.buk.util.JsonResult; import com.opensymphony.xwork2.ActionSupport; import java.text.ParseException; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * User: yfdai * Date: 14-11-6 * Time: 下午2:43 */ public class HotelAction extends ActionSupport { private int pageNo; private String cityCode; private String locationType; private String cityName; private String checkInDate; private String checkOutDate; private String hotelName; /** * 按照酒店星级过滤 */ private String star; private int districtId; private int zoneId; private String hotelCode; private String ratePlanCode; /** * 预定参数 * */ private String[] guestName; private String contactEmail; private String contactMobileNo; private String contactName; private String contactTelArea; private String contactTelExt; private String contactTelNum; //最晚到店时间 private String lateArrivalTime; //房间单价 private int price; //房间数量 private int roomCount; //房型代码 private String roomTypeCode; //房型名称 private String roomTypeName; //总价 private int total; private HotelSearchResult hotelSearchResult; private HotelAvailResult hotelAvailResult; private HotelRoomInfoResult hotelRoomInfoResult; private JsonResult jsonResult; private List<LocationDto> locations; private HotelService hotelService; private CtripHotelService ctripHotelService; public String search() { Date inDate=DateUtil.getCurDate(), outDate = DateUtil.getCurDate(); try { inDate = DateUtil.convertToDate(checkInDate, "yyyy-MM-dd"); outDate = DateUtil.convertToDate(checkOutDate, "yyyy-MM-dd"); } catch (ParseException e) { e.printStackTrace(); } hotelSearchResult = hotelService.searchHotel(cityCode, inDate, outDate, hotelName, pageNo, star, districtId, zoneId); return SUCCESS; } public String checkAvail() throws Exception { Date inDate=DateUtil.getCurDate(), outDate = DateUtil.getCurDate(); try { inDate = DateUtil.convertToDate(checkInDate, "yyyy-MM-dd"); outDate = DateUtil.convertToDate(checkOutDate, "yyyy-MM-dd"); } catch (ParseException e) { e.printStackTrace(); } Date lateArrivalTime = DateUtil.setTimeOnDate(inDate, 18, 0, 0); hotelAvailResult = ctripHotelService.checkHotelAvail(hotelCode, inDate, outDate, ratePlanCode, 1, 1, lateArrivalTime); return SUCCESS; } public String getLocationList() { if (locationType == null || locationType.length() == 0) { locations = new ArrayList<LocationDto>(); } else { locations = hotelService.getLocations(cityCode, locationType); } return SUCCESS; } public String getRoomInfo() throws Exception { Date inDate=DateUtil.getCurDate(), outDate = DateUtil.getCurDate(); try { inDate = DateUtil.convertToDate(checkInDate, "yyyy-MM-dd"); outDate = DateUtil.convertToDate(checkOutDate, "yyyy-MM-dd"); } catch (ParseException e) { e.printStackTrace(); } hotelRoomInfoResult = hotelService.getHotelRoomInfo(hotelCode, ratePlanCode, inDate, outDate); return SUCCESS; } public String createOrder() throws Exception { HotelOrder hotelOrder = new HotelOrder(); //hotelOrder.setCityCode(cityCode); try { hotelOrder.setCheckInDate(DateUtil.getDate(checkInDate, "yyyy-MM-dd")); hotelOrder.setCheckOutDate(DateUtil.getDate(checkOutDate, "yyyy-MM-dd")); } catch (ParseException e) { e.printStackTrace(); } HotelInfo hotelInfo = hotelService.getHotelInfoByHotelCode(hotelCode); hotelOrder.setHotel(hotelInfo); hotelOrder.setHotelCode(hotelCode); hotelOrder.setHotelName(hotelInfo.getHotelName()); hotelOrder.setCityName(hotelInfo.getCityName()); hotelOrder.setRoomTypeCode(roomTypeCode); hotelOrder.setRoomTypeName(getRoomTypeName()); hotelOrder.setRatePlanCode(ratePlanCode); hotelOrder.setPrice(price); hotelOrder.setRoomCount(roomCount); hotelOrder.setLateArriveTime(lateArrivalTime); hotelOrder.setTotal(total); ContactInfo contactInfo = new ContactInfo(); contactInfo.setContactName(contactName); //contactInfo.setConfirmType(confirmType); contactInfo.setContactMobile(contactMobileNo); contactInfo.setContactTelArea(contactTelArea); contactInfo.setContactTel(contactTelNum); contactInfo.setContactTelExt(contactTelExt); contactInfo.setContactEmail(contactEmail); //contactInfo.setContactFax(contactFax); hotelOrder.setContactInfo(contactInfo); List<HotelOrderGuest> guests = new ArrayList<HotelOrderGuest>(); for(String name: guestName) { if (name.length()==0) continue; HotelOrderGuest guest = new HotelOrderGuest(); guest.setName(name); guests.add(guest); guest.setOrder(hotelOrder); } hotelOrder.setGuests(guests); // int userId = UserAction.getSessionUserid(); // // User user = new User(); // user.setId(userId); // // hotelOrder.setUser(user); int retCode = hotelService.createHotelOrder(hotelOrder); jsonResult = new JsonResult(); jsonResult.setStatus("ER"); jsonResult.setDesc("Not yet implement this action"); if (retCode > 0) { jsonResult.setStatus("OK"); jsonResult.setDesc("Create hotel\'s order successfully, its id is " + retCode); } return SUCCESS; } public HotelService getHotelService() { return hotelService; } public void setHotelService(HotelService hotelService) { this.hotelService = hotelService; } public String getCityCode() { return cityCode; } public void setCityCode(String cityCode) { this.cityCode = cityCode; } public String getCityName() { return cityName; } public void setCityName(String cityName) { this.cityName = cityName; } public String getCheckInDate() { return checkInDate; } public void setCheckInDate(String checkInDate) { this.checkInDate = checkInDate; } public String getCheckOutDate() { return checkOutDate; } public void setCheckOutDate(String checkOutDate) { this.checkOutDate = checkOutDate; } public int getPageNo() { return pageNo; } public void setPageNo(int pageNo) { this.pageNo = pageNo; } public HotelSearchResult getHotelSearchResult() { return hotelSearchResult; } public void setHotelSearchResult(HotelSearchResult hotelSearchResult) { this.hotelSearchResult = hotelSearchResult; } public String getStar() { return star; } public void setStar(String star) { this.star = star; } public List<LocationDto> getLocations() { return locations; } public void setLocations(List<LocationDto> locations) { this.locations = locations; } public String getLocationType() { return locationType; } public void setLocationType(String locationType) { this.locationType = locationType; } public int getDistrictId() { return districtId; } public void setDistrictId(int districtId) { this.districtId = districtId; } public int getZoneId() { return zoneId; } public void setZoneId(int zoneId) { this.zoneId = zoneId; } public String getHotelName() { return hotelName; } public void setHotelName(String hotelName) { this.hotelName = hotelName; } public String getHotelCode() { return hotelCode; } public void setHotelCode(String hotelCode) { this.hotelCode = hotelCode; } public String getRatePlanCode() { return ratePlanCode; } public void setRatePlanCode(String ratePlanCode) { this.ratePlanCode = ratePlanCode; } public HotelAvailResult getHotelAvailResult() { return hotelAvailResult; } public void setHotelAvailResult(HotelAvailResult hotelAvailResult) { this.hotelAvailResult = hotelAvailResult; } public CtripHotelService getCtripHotelService() { return ctripHotelService; } public void setCtripHotelService(CtripHotelService ctripHotelService) { this.ctripHotelService = ctripHotelService; } public HotelRoomInfoResult getHotelRoomInfoResult() { return hotelRoomInfoResult; } public void setHotelRoomInfoResult(HotelRoomInfoResult hotelRoomInfoResult) { this.hotelRoomInfoResult = hotelRoomInfoResult; } public JsonResult getJsonResult() { return jsonResult; } public void setJsonResult(JsonResult jsonResult) { this.jsonResult = jsonResult; } public String[] getGuestName() { return guestName; } public void setGuestName(String[] guestName) { this.guestName = guestName; } public String getContactEmail() { return contactEmail; } public void setContactEmail(String contactEmail) { this.contactEmail = contactEmail; } public String getContactMobileNo() { return contactMobileNo; } public void setContactMobileNo(String contactMobileNo) { this.contactMobileNo = contactMobileNo; } public String getContactName() { return contactName; } public void setContactName(String contactName) { this.contactName = contactName; } public String getContactTelArea() { return contactTelArea; } public void setContactTelArea(String contactTelArea) { this.contactTelArea = contactTelArea; } public String getContactTelExt() { return contactTelExt; } public void setContactTelExt(String contactTelExt) { this.contactTelExt = contactTelExt; } public String getContactTelNum() { return contactTelNum; } public void setContactTelNum(String contactTelNum) { this.contactTelNum = contactTelNum; } public String getLateArrivalTime() { return lateArrivalTime; } public void setLateArrivalTime(String lateArrivalTime) { this.lateArrivalTime = lateArrivalTime; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public int getRoomCount() { return roomCount; } public void setRoomCount(int roomCount) { this.roomCount = roomCount; } public String getRoomTypeCode() { return roomTypeCode; } public void setRoomTypeCode(String roomTypeCode) { this.roomTypeCode = roomTypeCode; } public String getRoomTypeName() { return roomTypeName; } public void setRoomTypeName(String roomTypeName) { this.roomTypeName = roomTypeName; } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } }