/*
  * @see com.beike.dao.background.guest.GuestDao#queryGuestCountByConditions(com.beike.form.background.guest.GuestForm)
  */
 public int queryGuestCountByConditions(GuestForm guestForm) throws Exception {
   int totalRows = 0;
   StringBuilder sql = new StringBuilder();
   sql.append(
       "SELECT COUNT(1) FROM beiker_guest_info c LEFT JOIN beiker_brand b ON b.brand_id = c.brand_id  WHERE 1=1 ");
   if (guestForm.getGuestId() > 0) {
     sql.append(" AND c.guest_id = ").append(guestForm.getGuestId());
   }
   if (StringUtils.validNull(guestForm.getGuestCnName())) {
     sql.append(" AND c.guest_cn_name LIKE ")
         .append("'%" + guestForm.getGuestCnName().trim() + "%'");
   }
   if (StringUtils.validNull(guestForm.getBrandName())) {
     sql.append(" AND b.brand_name LIKE ").append("'%" + guestForm.getBrandName().trim() + "%'");
   }
   if (StringUtils.validNull(guestForm.getGuestAddress())) {
     sql.append(" AND c.guest_address LIKE ")
         .append("'%" + guestForm.getGuestAddress().trim() + "%'");
   }
   if (guestForm.getBrandId() > 0) {
     sql.append(" AND c.brand_id = ").append(guestForm.getBrandId());
   }
   totalRows = this.getJdbcTemplate().queryForInt(sql.toString());
   return totalRows;
 }
 /*
  * @see com.beike.dao.background.guest.GuestDao#queryGuestByConditions(com.beike.form.background.guest.GuestForm, int, int)
  */
 @SuppressWarnings("unchecked")
 public List<Guest> queryGuestByConditions(GuestForm guestForm, int startRow, int pageSize)
     throws Exception {
   List tempList = null;
   List<Guest> guestList = new ArrayList<Guest>();
   StringBuilder sql = new StringBuilder();
   sql.append(
       "SELECT c.guest_id guest_id,c.guest_cn_name guest_cn_name,b.brand_name brand_name,c.guest_address guest_address,c.guest_status guest_status,c.brand_id brand_id FROM beiker_guest_info c ");
   sql.append("LEFT JOIN beiker_brand b ON b.brand_id = c.brand_id  WHERE 1=1 ");
   if (guestForm.getGuestId() > 0) {
     sql.append(" AND c.guest_id = ").append(guestForm.getGuestId());
   }
   if (StringUtils.validNull(guestForm.getGuestCnName())) {
     sql.append(" AND c.guest_cn_name LIKE ")
         .append("'%" + guestForm.getGuestCnName().trim() + "%'");
   }
   if (StringUtils.validNull(guestForm.getBrandName())) {
     sql.append(" AND b.brand_name LIKE ").append("'%" + guestForm.getBrandName().trim() + "%'");
   }
   if (StringUtils.validNull(guestForm.getGuestAddress())) {
     sql.append(" AND c.guest_address LIKE ")
         .append("'%" + guestForm.getGuestAddress().trim() + "%'");
   }
   if (guestForm.getBrandId() > 0) {
     sql.append(" AND c.brand_id = ").append(guestForm.getBrandId());
   }
   sql.append(" ORDER BY guest_id DESC LIMIT ?,? ");
   Object[] params = new Object[] {startRow, pageSize};
   int[] types = new int[] {Types.INTEGER, Types.INTEGER};
   tempList = this.getJdbcTemplate().queryForList(sql.toString(), params, types);
   if (null != tempList && tempList.size() > 0) {
     guestList = this.convertResultToObjectList(tempList);
   }
   return guestList;
 }
 /**
  * 将查询结果元素(map对象)转化为具体对象
  *
  * @param result jdbcTemplate返回的查询结果元素(map对象)
  * @return 具体的对象类型
  * @author lvjx
  */
 @SuppressWarnings("unchecked")
 private Guest convertResultMapToObject(Map result) throws Exception {
   Guest obj = new Guest();
   if (result != null) {
     Long guestId = (Long) result.get("guest_id");
     if (null != guestId) {
       obj.setGuestId(guestId.intValue());
     }
     Long brandId = (Long) result.get("brand_id");
     if (null != brandId) {
       obj.setBrandId(brandId.intValue());
     }
     if (StringUtils.validNull((String) result.get("guest_cn_name"))) {
       obj.setGuestCnName(result.get("guest_cn_name").toString());
     }
     if (StringUtils.validNull((String) result.get("guest_type"))) {
       obj.setGuestType(result.get("guest_type").toString());
     }
     Long guestCountryId = (Long) result.get("guest_country_id");
     if (null != guestCountryId) {
       obj.setGuestCountryId(guestCountryId.intValue());
     }
     Long guestProvinceId = (Long) result.get("guest_province_id");
     if (null != guestProvinceId) {
       obj.setGuestProvinceId(guestProvinceId.intValue());
     }
     Long guestCityId = (Long) result.get("guest_city_id");
     if (null != guestCityId) {
       obj.setGuestCityId(guestCityId.intValue());
     }
     if (StringUtils.validNull((String) result.get("guest_address"))) {
       obj.setGuestAddress(result.get("guest_address").toString());
     }
     if (StringUtils.validNull((String) result.get("guest_account"))) {
       obj.setGuestAccount(result.get("guest_account").toString());
     }
     if (StringUtils.validNull((String) result.get("guest_account_bank"))) {
       obj.setGuestAccountBank(result.get("guest_account_bank").toString());
     }
     if (StringUtils.validNull((String) result.get("guest_contract_no"))) {
       obj.setGuestContractNo(result.get("guest_contract_no").toString());
     }
     if (StringUtils.validNull((String) result.get("guest_email"))) {
       obj.setGuestEmail(result.get("guest_email").toString());
     }
     if (StringUtils.validNull((String) result.get("guest_status"))) {
       obj.setGuestStatus(result.get("guest_status").toString());
     }
     if (StringUtils.validNull((String) result.get("brand_name"))) {
       obj.setBrandName(result.get("brand_name").toString());
     }
   }
   return obj;
 }
  /*
   * @see com.beike.service.background.goods.GoodsService#isTopGoods(com.beike.form.background.top.GoodsForm)
   */
  public String editGoodsTop(GoodsForm goodsForm) throws Exception {
    String result = null;
    TopForm topForm = null;
    String goodsId = goodsDao.queryGoodsTop(goodsForm);
    if (StringUtils.validNull(goodsId)) {
      if (Integer.parseInt(goodsId) <= 0) {
        result = goodsDao.editGoodsIsTop(goodsForm);
        topForm = new TopForm();
        topForm.setTopOldGoodsId(goodsForm.getGoodsId());
        topForm.setTopNewGoodsId(goodsForm.getGoodsId());
        topForm.setTopStatus("0");
        goodsDao.addGoodsTop(topForm);
      } else {
        GoodsForm form = new GoodsForm();
        form.setGoodsId(Integer.parseInt(goodsId));
        form.setGoodsIsTop("0");
        result = goodsDao.editGoodsIsTop(form); // 首先将原先置顶的修改为不置顶
        // boolean flag = goodsDao.queryTopIsExist(goodsId);

        topForm = new TopForm();
        if (StringUtils.validNull(result) && Integer.parseInt(result) > 0) {
          result = goodsDao.editGoodsIsTop(goodsForm); // 置顶当前要置顶的内容
        }
        topForm.setTopOldGoodsId(Integer.parseInt(goodsId));
        topForm.setTopNewGoodsId(goodsForm.getGoodsId());
        topForm.setTopStatus("0");
        // if(flag){
        // result = goodsDao.updateGoodsTop(topForm);
        goodsDao.addGoodsTop(topForm);
        /*}else{
        	topForm.setTopOldGoodsId(goodsId);
        	topForm.setTopNewGoodsId(goodsForm.getGoodsId());
        	topForm.setTopStatus("0");
        	result = goodsDao.addGoodsTop(topForm);
        }*/
      }
    }
    return result;
  }
 /*
  * @see com.beike.dao.background.guest.GuestDao#validatorGuestContractNo(com.beike.form.background.guest.GuestForm)
  */
 public boolean validatorGuestContractNo(GuestForm guestForm) throws Exception {
   boolean flag = false;
   StringBuilder sql = new StringBuilder();
   sql.append("SELECT COUNT(1) FROM beiker_guest_info WHERE guest_contract_no = ? ");
   if (StringUtils.validNull(String.valueOf(guestForm.getGuestId()))) {
     sql.append(" AND guest_id != ").append(guestForm.getGuestId());
   }
   Object[] params = new Object[] {guestForm.getGuestContractNo().trim()};
   int[] types = new int[] {Types.VARCHAR};
   int count = this.getJdbcTemplate().queryForInt(sql.toString(), params, types);
   if (count > 0) {
     flag = true;
   }
   return flag;
 }