@Override
  public List<Shop> getAllShops() throws Exception {
    List<Shop> list = new ArrayList<Shop>();
    SqlSession sqlSession = null;

    try {
      sqlSession = SessionUtils.getSession();

      ShopMapper shopMapper = sqlSession.getMapper(ShopMapper.class);

      list = shopMapper.selectAllShops();

    } catch (Exception e) {
      throw e;
    } finally {
      SessionUtils.closeSession(sqlSession);
    }

    return list;
  }
  @Override
  public List<Object> querySell(Date start, Date end, int shopId, int orderId) throws Exception {

    List<Object> list = new ArrayList<Object>();
    SqlSession sqlSession = null;

    try {
      sqlSession = SessionUtils.getSession();

      ProductMapper productMapper = sqlSession.getMapper(ProductMapper.class);
      SellMapper sellMapper = sqlSession.getMapper(SellMapper.class);
      SellDetailMapper sellDetailMapper = sqlSession.getMapper(SellDetailMapper.class);
      UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
      ShopMapper shopMapper = sqlSession.getMapper(ShopMapper.class);

      if (orderId != -1) {
        Sell sell = sellMapper.selectByPrimaryKey(orderId);

        if (sell != null) {
          Map<String, Object> map = new HashMap<String, Object>();
          map.put("oId", sell.getsId());
          map.put("date", sell.getsDate());
          User user = userMapper.selectByPrimaryKey(sell.getuId());
          map.put("user", user.getuName());
          List<SellDetail> sellDetails = sellDetailMapper.selectBySellId(sell.getsId());
          int price = 0;
          for (SellDetail sellDetail : sellDetails) {
            Product product = productMapper.selectByPrimaryKey(sellDetail.getpId());
            price += sellDetail.getsNum() * product.getpPrice();
          }
          map.put("price", price);
          Shop shop = shopMapper.selectByPrimaryKey(sell.getShopId());
          map.put("shop", shop.getsName());
          list.add(map);
        }

        return list;
      } else {
        List<Sell> sells = null;
        if (shopId == 0) {
          sells = sellMapper.selectAll();
        } else {
          sells = sellMapper.selectByShopId(shopId);
        }

        for (Sell sell : sells) {
          if ((end == null ? true : sell.getsDate().before(end))
              && (start == null ? true : sell.getsDate().after(start))) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("oId", sell.getsId());
            map.put("date", sell.getsDate());
            User user = userMapper.selectByPrimaryKey(sell.getuId());
            map.put("user", user.getuName());
            List<SellDetail> sellDetails = sellDetailMapper.selectBySellId(sell.getShopId());
            int price = 0;
            for (SellDetail sellDetail : sellDetails) {
              Product product = productMapper.selectByPrimaryKey(sellDetail.getpId());
              price += sellDetail.getsNum() * product.getpPrice();
            }
            map.put("price", price);
            Shop shop = shopMapper.selectByPrimaryKey(sell.getShopId());
            map.put("shop", shop.getsName());
            list.add(map);
          }
        }
      }
    } catch (Exception e) {
      throw e;
    } finally {
      SessionUtils.closeSession(sqlSession);
    }

    return list;
  }