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

import com.ym.mec.biz.dal.dao.GoodsDao;
import com.ym.mec.biz.dal.entity.Goods;
import com.ym.mec.biz.dal.page.ReplacementInstrumentQueryInfo;
import com.ym.mec.common.dal.BaseDAO;
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.ReplacementInstrument;
import com.ym.mec.biz.service.ReplacementInstrumentService;
import com.ym.mec.biz.dal.dao.ReplacementInstrumentDao;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReplacementInstrumentServiceImpl extends BaseServiceImpl<Integer, ReplacementInstrument> implements ReplacementInstrumentService {

    @Autowired
    private ReplacementInstrumentDao replacementInstrumentDao;
    @Autowired
    private GoodsDao goodsDao;

    @Override
    public BaseDAO<Integer, ReplacementInstrument> getDAO() {
        return replacementInstrumentDao;
    }

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

        List<ReplacementInstrument> dataList = new ArrayList<>();
        int count = goodsDao.getReplacementInstrumentCount(params);

        if (count > 0) {
            pageInfo.setTotal(count);
            params.put("offset", pageInfo.getOffset());
            dataList = goodsDao.getReplacementGoodsPage(params);
        }
        pageInfo.setRows(dataList);
        return pageInfo;
    }
}