package com.ym.mec.biz.service.impl;

import java.util.*;

import com.ym.mec.biz.dal.page.GoodsProcurementQueryInfo;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import com.ym.mec.util.collection.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import com.ym.mec.biz.dal.entity.GoodsProcurement;
import com.ym.mec.biz.service.GoodsProcurementService;
import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
import org.springframework.stereotype.Service;

@Service
public class GoodsProcurementServiceImpl extends BaseServiceImpl<Long, GoodsProcurement> implements GoodsProcurementService {
	
	@Autowired
	private GoodsProcurementDao goodsProcurementDao;

	@Override
	public BaseDAO<Long, GoodsProcurement> getDAO() {
		return goodsProcurementDao;
	}

	@Override
	public PageInfo<GoodsProcurement> queryGoodsProcurements(GoodsProcurementQueryInfo queryInfo) {
		PageInfo<GoodsProcurement> pageInfo = new PageInfo(queryInfo.getPage(), queryInfo.getRows());
		Map<String, Object> params = new HashMap<String, Object>();
		MapUtil.populateMap(params, queryInfo);

		List<GoodsProcurement> dataList = null;
		int count = goodsProcurementDao.countGoodsProcurements(params);
		if (count > 0) {
			pageInfo.setTotal(count);
			params.put("offset", pageInfo.getOffset());
			dataList = goodsProcurementDao.queryGoodsProcurements(params);
		}
		if (count == 0) {
			dataList = new ArrayList();
		}
		pageInfo.setRows(dataList);
		return pageInfo;
	}
}
