package com.jpsoft.shinestar.modules.business.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.business.dao.BillPushGoodsDAO;
import com.jpsoft.shinestar.modules.business.entity.BillPushGoods;
import com.jpsoft.shinestar.modules.business.service.BillPushGoodsService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="billPushGoodsService")
public class BillPushGoodsServiceImpl implements BillPushGoodsService {
	@Resource(name="billPushGoodsDAO")
	private BillPushGoodsDAO billPushGoodsDAO;

	@Override
	public BillPushGoods get(String id) {
		// TODO Auto-generated method stub
		return billPushGoodsDAO.get(id);
	}

	@Override
	public int insert(BillPushGoods model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());

		return billPushGoodsDAO.insert(model);
	}

	@Override
	public int update(BillPushGoods model) {
		// TODO Auto-generated method stub
		return billPushGoodsDAO.update(model);
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return billPushGoodsDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = billPushGoodsDAO.exist(id);

		return count > 0 ? true : false;
	}

	@Override
	public List<BillPushGoods> list() {
		// TODO Auto-generated method stub
		return billPushGoodsDAO.list();
	}

	@Override
	public Page<BillPushGoods> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
		Page<BillPushGoods> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
			billPushGoodsDAO.search(searchParams,sortList);
		});

		return page;
	}

	@Override
	public Page<BillPushGoods> pageSearchStatistics(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
		Page<BillPushGoods> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
			billPushGoodsDAO.searchStatistics(searchParams,sortList);
		});

		return page;
	}

	@Override
	public List<BillPushGoods> findByBillPushId(String billPushId) {
		return billPushGoodsDAO.findByBillPushId(billPushId);
	}

	@Override
	public BillPushGoods findLastByCheckinInfoIdAndGoodsId(String checkinInfoId, String goodsId) {
		return billPushGoodsDAO.findLastByCheckinInfoIdAndGoodsId(checkinInfoId,goodsId);
	}
}