package market.Lms.Consumable.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Lms.Consumable.mapper.LmsConsumableStockInfoMapper;
import market.Lms.Consumable.service.LmsConsumableStockInfoService;
import market.Lms.Consumable.vo.LmsConsumableStockInfo;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path="LmsConsumableStockInfo")
public class LmsConsumableStockInfoServiceImpl extends BaseServiceImpl<LmsConsumableStockInfo,Object> implements LmsConsumableStockInfoService{

	//新增
	public String doAdd(LmsConsumableStockInfo stock){
		String id = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
		stock.setBill_no(id);
		stock.setCreate_time(new Date());
		this.getMapper(LmsConsumableStockInfoMapper.class).insert(stock);
		return id;
	}

	//删除
	public void doDelete(LmsConsumableStockInfo stock){
		this.getMapper(LmsConsumableStockInfoMapper.class).delete(stock.getBill_no());
	}

	//修改
	public void doUpdate(LmsConsumableStockInfo stock){
		this.getMapper(LmsConsumableStockInfoMapper.class).update(stock);
	}

	//查询
	public LmsConsumableStockInfo doQuery(String stockNo){
		LmsConsumableStockInfo stock = new LmsConsumableStockInfo();
		stock = this.getMapper(LmsConsumableStockInfoMapper.class).findById(stockNo);
		return stock;
	}

	//=============================================APP===================================
	/**App端返回收发存列表
	 * @param sum
	 * @return
	 */
	public List<LmsConsumableStockInfo> doQueryApp(CommonPage<LmsConsumableStockInfo> sum){
		LmsConsumableStockInfo stock = sum.getObject();
		int pageIndex = sum.getPageIndex();
		int pageSize = sum.getPageSize();
		List<LmsConsumableStockInfo> stockList = new ArrayList<LmsConsumableStockInfo>();
		try{
			stockList = this.getMapper(LmsConsumableStockInfoMapper.class).doQueryList(stock, pageIndex, pageSize);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<LmsConsumableStockInfo>();
		}
		return stockList;
	}
}
