@Override
  public List<Object> getProductByShop(int shopId) throws Exception {
    List<Object> list = new ArrayList<Object>();
    SqlSession sqlSession = null;

    try {
      sqlSession = SessionUtils.getSession();

      StockMapper stockMapper = sqlSession.getMapper(StockMapper.class);
      ProductMapper productMapper = sqlSession.getMapper(ProductMapper.class);

      List<Stock> stocks = stockMapper.selectByshopId(shopId);

      for (Stock stock : stocks) {
        Map<String, Object> map = new HashMap<String, Object>();
        Product product = productMapper.selectByPrimaryKey(stock.getpId());

        map.put("name", product.getpName());
        map.put("num", stock.getsNum());
        map.put("pid", stock.getpId());
        map.put("price", product.getpPrice());

        list.add(map);
      }

    } 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;
  }