/**
  * @author zhang.jie 页面跳转-酒店详情
  * @param request
  * @return 2015-9-21
  */
 @PolicyJournal(accessLevel = AccessLevel.PRIVATE)
 @RequestMapping("/to_hotelRoomdetail_dialog")
 public ModelAndView to_hotelRoomdetail_dialog(HttpServletRequest request, String id) {
   ModelAndView mav = new ModelAndView("/hotelroom/to_roomDetail_dialog");
   // 根据id查询酒店客房信息
   Map<String, Object> map = this.hotelRoomService.selectHotelRoomByPk(id);
   // 根据客房id查询产品
   HotelRoomPlanBo hotelRoomPlan = new HotelRoomPlanBo();
   hotelRoomPlan.setRoomId(id);
   hotelRoomPlan.setStatus("1");
   List<Map<String, Object>> list =
       this.hotelRoomPlanService.selectHotelRoomPlanByExample(hotelRoomPlan);
   mav.addObject("list", list);
   mav.addObject("map", map);
   return mav;
 }
 /**
  * 客房删除方法
  *
  * @author chivalry
  * @param request
  * @return 2015-10-13
  */
 @SuppressWarnings("rawtypes")
 @PolicyJournal(accessLevel = AccessLevel.PRIVATE)
 @RequestMapping(
     value = "/do_delete_hotelRoom",
     method = {RequestMethod.POST})
 @ResponseBody
 public Response do_delete_hotelRoom(HttpServletRequest request, String id) {
   // 返回对象
   Response response = new Response();
   HotelRoomBo hotelRoom = new HotelRoomBo();
   hotelRoom.setId(id);
   hotelRoom.setStatus("0");
   int results = this.hotelRoomService.updateHotelRoom(hotelRoom);
   HotelRoomPlanBo hotelRoomPlan = new HotelRoomPlanBo();
   hotelRoomPlan.setRoomId(id);
   this.hotelRoomPlanService.deleteRoomPlanByPk(hotelRoomPlan);
   if (results == 1) {
     response.setSucceessMessage("删除成功");
   } else {
     response.setFailMessage("删除失败");
   }
   return response;
 }
  /**
   * @author zhang.jie 页面跳转-酒店详情修改页面
   * @param request
   * @return 2015-9-21
   */
  @PolicyJournal(accessLevel = AccessLevel.PRIVATE)
  @RequestMapping("/to_roomedit_dialog")
  public ModelAndView to_roomedit_dialog(HttpServletRequest request, String id) {
    String agentId = null;
    // 非商户
    String isAgent = "0";
    LoginUser user = LoginSessionUtil.getSystemSession(request);
    if (user.getAgentId() != null) {
      agentId = user.getAgentId().toString();
      // 商户
      isAgent = "1";
    }
    Page<List<Map<String, Object>>> page = Page.getPage(request);
    List<Map<String, Object>> list1 = hotelRoomService.selectHotelNameByagentId(agentId);
    ModelAndView mav = null;
    if (isAgent.equals("0")) {
      mav = new ModelAndView("/hotelroom/to_room_edit_admin");
    } else if (isAgent.equals("1")) {
      mav = new ModelAndView("/hotelroom/to_room_edit");
    }

    // 根据id查询酒店客房信息
    Map<String, Object> map = this.hotelRoomService.selectHotelRoomByPk(id);
    // 根据客房id查询产品
    HotelRoomPlanBo hotelRoomPlan = new HotelRoomPlanBo();
    hotelRoomPlan.setRoomId(id);
    hotelRoomPlan.setStatus("1");
    List<Map<String, Object>> list =
        this.hotelRoomPlanService.selectHotelRoomPlanByExample(hotelRoomPlan);
    mav.addObject("list", list);
    mav.addObject("planSize", list.size());
    mav.addObject("map", map);
    mav.addObject("list1", list1);
    mav.addObject("isAgent", isAgent);
    return mav;
  }
  /**
   * 酒店客房修改
   *
   * @author chivalry
   * @param request
   * @return 2015-10-12
   */
  @SuppressWarnings("rawtypes")
  @PolicyJournal(accessLevel = AccessLevel.PRIVATE)
  @RequestMapping(
      value = "/do_edit_hotelRoom",
      method = {RequestMethod.POST})
  @ResponseBody
  public Response do_edit_hotelRoom(
      HttpServletRequest request,
      @Valid HotelRoomBo hotelRoom,
      BindingResult result,
      HotelRoomPlanBo hotelRoomPlan) {
    // 返回对象
    Response response = new Response(); // 服务端验证
    if (result.hasErrors()) {
      ValidateParamUtils.analyzeErrors(result, response);
      return response;
    }
    int results = 1;
    results = this.hotelRoomService.updateHotelRoom(hotelRoom);
    // 根据客房主键ID删除客房产品
    hotelRoomPlan.setId(null);
    hotelRoomPlan.setRoomId(hotelRoom.getId());
    results = this.hotelRoomPlanService.deleteRoomPlanByPk(hotelRoomPlan);
    // 新增客房产品
    hotelRoomPlan.setHotelId(hotelRoom.getHotelId());
    hotelRoomPlan.setBedType(hotelRoom.getBedType());
    hotelRoomPlan.setRoomStatus(hotelRoom.getRoomStatus());

    String[] breakfastTypeStr = request.getParameterValues("isBreakfast");
    String[] cancelRuleStr = request.getParameterValues("cancelRule");
    String[] discountAmountStr = request.getParameterValues("discount");
    String[] cashBackStr = request.getParameterValues("cashBack");
    String[] roomPlanName = request.getParameterValues("roomPlanName");
    String[] payType = request.getParameterValues("payType");
    String[] campaignDaysStr = request.getParameterValues("campaignDays");
    List<HotelRoomPlanBo> list = new ArrayList<HotelRoomPlanBo>();
    if (breakfastTypeStr != null) {
      for (int i = 0; i < breakfastTypeStr.length; i++) {
        hotelRoomPlan.setBreakfastType(breakfastTypeStr[i]);
        hotelRoomPlan.setCancelRule(cancelRuleStr[i]);
        hotelRoomPlan.setDiscountAmount(discountAmountStr[i]);
        hotelRoomPlan.setCashBack(cashBackStr[i]);
        hotelRoomPlan.setRoomPlanName(roomPlanName[i]);
        hotelRoomPlan.setPayType(payType[i]);
        hotelRoomPlan.setCampaignDays(campaignDaysStr[i]);
        if (hotelRoomPlan.getDiscountAmount() == null
            || StringUtils.isBlank(hotelRoomPlan.getDiscountAmount())) {
          response.setFailMessage("折扣未填写完整!");
          return response;
        }
        if (hotelRoomPlan.getCashBack() == null
            || StringUtils.isBlank(hotelRoomPlan.getCashBack())) {
          response.setFailMessage("返现未填写完整!");
          return response;
        }
        if (hotelRoomPlan.getRoomPlanName() == null
            || StringUtils.isBlank(hotelRoomPlan.getRoomPlanName())) {
          response.setFailMessage("产品名称未填写完整!");
          return response;
        }
        if (hotelRoomPlan.getCampaignDays() == null
            || StringUtils.isBlank(hotelRoomPlan.getCampaignDays())) {
          response.setFailMessage("起订天数未填写完整!");
          return response;
        }
        double price = 0;
        double discountAmount = Double.parseDouble(discountAmountStr[i]);
        double cashBack = Double.parseDouble(cashBackStr[i]);
        double prices = Double.parseDouble(hotelRoom.getPrice());
        price = prices * discountAmount / 10 + cashBack;
        hotelRoomPlan.setPrice(Double.toString(price));
        HotelRoomPlanBo hotelRoomPlans = new HotelRoomPlanBo();
        BeanUtils.copyProperties(hotelRoomPlan, hotelRoomPlans);
        list.add(hotelRoomPlans);
      }
    }
    if (list != null
        && list.size() > 0
        && list.get(0).getBreakfastType() != null
        && list.get(0).getBreakfastType() != "") {
      results = this.hotelRoomPlanService.insertHotelRoomPlan(list);
    }
    if (results >= 0) {
      response.setSucceessMessage("修改成功");
    } else {
      response.setFailMessage("修改失败");
    }
    return response;
  }
  /**
   * 酒店房间新增方法
   *
   * @author chivalry
   * @param request
   * @return 2015-09-21
   */
  @SuppressWarnings("rawtypes")
  @PolicyJournal(accessLevel = AccessLevel.PRIVATE)
  @RequestMapping(
      value = "/do_hotelRoom_add",
      method = {RequestMethod.POST})
  @ResponseBody
  public Response do_hotelRoom_add(
      HttpServletRequest request,
      @Valid HotelRoomBo hotelRoom,
      BindingResult result,
      HotelRoomPlanBo hotelRoomPlan) {
    // 返回对象
    LoginUser user = LoginSessionUtil.getSystemSession(request);
    // 判断当前用户是否为加盟商
    if (user.getAgentId() != null) {
      String id = user.getAgentId().toString();
      hotelRoomPlan.setAgentId(id);
    } else {
      hotelRoomPlan.setAgentId("0");
    }
    Response response = new Response(); // 服务端验证
    if (result.hasErrors()) {
      ValidateParamUtils.analyzeErrors(result, response);
      return response;
    }

    // 返回插入酒店信息主键ID,设置房间产品信息
    // 插入图片关联关系
    String imageIds = request.getParameter("imageIds");
    String[] imageidsStr = imageIds.split(",");
    List<Map<String, Object>> imageList = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < imageidsStr.length; i++) {
      if (StringUtils.isNotBlank(imageidsStr[i])) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("roomId", hotelRoom.getId());
        map.put("hotelId", null);
        map.put("groupHotelId", null);
        map.put("imageId", imageidsStr[i]);
        imageList.add(map);
      }
    }
    //		 if(imageList!=null&&imageList.size()>0&&imageList.get(0).get("imageId")!=null
    //	    		 &&imageList.get(0).get("imageId")!=""){
    //			 imageService.insertRelation(imageList);
    //		 }

    hotelRoomPlan.setHotelId(hotelRoom.getHotelId());
    hotelRoomPlan.setBedType(hotelRoom.getBedType());
    hotelRoomPlan.setRoomId(hotelRoom.getId());
    hotelRoomPlan.setRoomStatus(hotelRoom.getRoomStatus());

    String[] breakfastTypeStr = request.getParameterValues("isBreakfast");
    String[] cancelRuleStr = request.getParameterValues("cancelRule");
    String[] discountAmountStr = request.getParameterValues("discount");
    String[] cashBackStr = request.getParameterValues("cashBack");
    String[] roomPlanName = request.getParameterValues("roomPlanName");
    String[] payType = request.getParameterValues("payType");
    String[] campaignDaysStr = request.getParameterValues("campaignDays");

    List<HotelRoomPlanBo> list = new ArrayList<HotelRoomPlanBo>();
    for (int i = 0; i < breakfastTypeStr.length; i++) {
      hotelRoomPlan.setBreakfastType(breakfastTypeStr[i]);
      hotelRoomPlan.setCancelRule(cancelRuleStr[i]);
      hotelRoomPlan.setDiscountAmount(discountAmountStr[i]);
      hotelRoomPlan.setCashBack(cashBackStr[i]);
      hotelRoomPlan.setRoomPlanName(roomPlanName[i]);
      hotelRoomPlan.setPayType(payType[i]);
      hotelRoomPlan.setCampaignDays(campaignDaysStr[i]);
      if (hotelRoomPlan.getDiscountAmount() == null
          || StringUtils.isBlank(hotelRoomPlan.getDiscountAmount())) {
        response.setFailMessage("折扣未填写完整!");
        return response;
      }
      if (hotelRoomPlan.getCashBack() == null || StringUtils.isBlank(hotelRoomPlan.getCashBack())) {
        response.setFailMessage("返现未填写完整!");
        return response;
      }
      if (hotelRoomPlan.getRoomPlanName() == null
          || StringUtils.isBlank(hotelRoomPlan.getRoomPlanName())) {
        response.setFailMessage("产品名称未填写完整!");
        return response;
      }
      if (hotelRoomPlan.getCampaignDays() == null
          || StringUtils.isBlank(hotelRoomPlan.getCampaignDays())) {
        response.setFailMessage("起订天数未填写完整!");
        return response;
      }
      double price = 0;
      double discountAmount = Double.parseDouble(discountAmountStr[i]);
      double cashBack = Double.parseDouble(cashBackStr[i]);
      double prices = Double.parseDouble(hotelRoom.getPrice());
      price = prices * discountAmount / 10 + cashBack;
      hotelRoomPlan.setPrice(Double.toString(price));
      HotelRoomPlanBo hotelRoomPlans = new HotelRoomPlanBo();
      BeanUtils.copyProperties(hotelRoomPlan, hotelRoomPlans);
      list.add(hotelRoomPlans);
    }
    //		if(list!=null&&list.size()>0&&list.get(0).getBreakfastType()!=null
    //	    		 &&list.get(0).getBreakfastType()!=""){
    //		results=this.hotelRoomPlanService.insertHotelRoomPlan(list);
    //		}
    int results = this.hotelRoomService.insertHotelRoomAndOther(hotelRoom, imageList, list);
    if (results >= 1) {
      response.setSucceessMessage("添加成功");
    } else {
      response.setFailMessage("添加失败");
    }
    return response;
  }