/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-12-28
 * 描述            ：仓库管理-库存信息表修改备份
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Lms.Warehouse.impl;
import java.util.HashMap;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailBfMapper;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.service.YdmProductDetailBfService;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Lms.Warehouse.vo.YdmProductDetailBf;
import market.Lms.Warehouse.vo.YdmProductInlist;
import market.Lms.Warehouse.vo.YdmProductOutlist;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.transaction.annotation.Transactional;

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

@SuppressWarnings("rawtypes")
@RemoteService(path="YdmProductDetailBfService")
public class YdmProductDetailBfServiceImpl extends BaseServiceImpl<YdmProductDetailBf,Object> implements YdmProductDetailBfService {

	/**
	 * 将库存数据进行备份
	 * @author 赵淋支 
	 * @date   2018年12月28日
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doAddDetailBf(CommonPage<YdmProductDetail> cp) throws Exception{
		ResultModel rm =new ResultModel();
		List<YdmProductDetail> ypdList = cp.getObjectList();
		for (YdmProductDetail YPD : ypdList) {
			YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(YPD.getCoilno(), null);
			if (ypd!=null) {
				YdmProductDetailBf ypdBF = new YdmProductDetailBf();
				//1.除序号外全部复制
				BeanUtils.copyProperties(ypdBF, ypd);
				//2.设置序号
				String condition = "coilno = '"+ypd.getCoilno()+"'";
				List<YdmProductDetailBf> list = this.getMapper(YdmProductDetailBfMapper.class).findWithCondition(null, condition, "seq desc", 0, 0);
				if (list!=null && list.size()>0) {
					ypdBF.setSeq(list.get(0).getSeq()+1);
				}else {
					ypdBF.setSeq(1);
				}
				//3.复制备份
				this.getMapper(YdmProductDetailBfMapper.class).insert(ypdBF);				
			}
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 优特钢库存报表：入库量 object[仓库storageattr memo年份]
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQuaryInByYpi(CommonPage<YdmProductInlist> cp) throws Exception{
		ResultModel rm =new ResultModel();
		YdmProductInlist ypi = cp.getObject();
		List<HashMap> list = this.getMapper(YdmProductDetailBfMapper.class).doQuaryInByYpi(ypi);
		rm.setData(list);
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 优特钢库存报表：出库量 object[仓库storageattr memo年份]
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQuaryOutByYpo(CommonPage<YdmProductOutlist> cp) throws Exception{
		ResultModel rm =new ResultModel();
		YdmProductOutlist ypo = cp.getObject();
		List<HashMap> list = this.getMapper(YdmProductDetailBfMapper.class).doQuaryOutByYpo(ypo);
		rm.setData(list);
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 优特钢库存报表：出库量 object[仓库storageattr memo年份]
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQuaryDetailByMonthEnd(CommonPage<YdmProductDetail> cp) throws Exception{
		ResultModel rm =new ResultModel();
		YdmProductDetail ypd = cp.getObject();
		List<HashMap> list = this.getMapper(YdmProductDetailBfMapper.class).doQuaryDetailByMonthEnd(ypd);
		rm.setData(list);
		rm.setState("200");
		return rm;
	}

}
