/***文档注释***********************************************
 * 作者            ：      易鑫
 * 创建日期     ：2018-02-6
 * 描述            ：检验委托明细表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.qcm.service.impl;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.qcm.mapper.JhySampleConsignDMapper;
import market.Qms.qcm.service.JhySampleConsignDService;
import market.Qms.qcm.vo.JhySampleConsignD;
import market.Qms.qcm.vo.JhySampleConsignDItem;

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

@RemoteService(path="JhySampleConsignDService")
public class JhySampleConsignDServiceImpl extends BaseServiceImpl<JhySampleConsignD, String> implements JhySampleConsignDService {

	
	/**
	 * 委托从表
	 * SQL实现
	 * 条件+分页
	 * */
	public ResultModel doQueryWebBySQL(CommonPage<JhySampleConsignD> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<JhySampleConsignD> pm = new PageModel<JhySampleConsignD>(pageIndex,pageSize);
		try
		{																										
		
			rm.setData(this.getMapper(JhySampleConsignDMapper.class).QuerybySql
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getSmpNo(), cp.getObject().getHeatNo(),cp.getObject().getBatchNo(),cp.getMemo1(),cp.getMemo2(),cp.getObject().getStatus()));
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 插入委托从表
	 * SQL实现
	 * 条件+分页
	 * */
	public ResultModel doInsertD(CommonPage<JhySampleConsignD> cp)
	{
		ResultModel rm=new ResultModel();
		JhySampleConsignD  JhySamp  = new JhySampleConsignD();
		JhySampleConsignDItem JhySampItem = new JhySampleConsignDItem();
		
		try {
			JhySamp = cp.getObject();
			
			//JhySampleConsignD dd = this.getMapper(JhySampleConsignDMapper.class).GetChemBysql(cp.getObject().getSmpNo(), cp.getObject().getFreqCode());
			
			
			String CONSIGN_NO = this.getMapper(JhySampleConsignDMapper.class).GetMaxCode();
			String Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(cp.getObject().getSmpNo());
			
			
			JhySamp.setConsignNo(CONSIGN_NO);
			this.getMapper(JhySampleConsignDMapper.class).insert(JhySamp);
			
			this.getMapper(JhySampleConsignDMapper.class).doInsertDItem(cp.getObject().getSmpNo(), Seq,CONSIGN_NO);
			
			Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(cp.getObject().getSmpNo());
			this.getMapper(JhySampleConsignDMapper.class).doInsertDItem2(cp.getObject().getSmpNo(), Seq,cp.getObject().getAllItemCode());

			
			rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
		}
		
		return rm;
		
		
	}
	
	/**
	 * 修改委托从表
	 * SQL实现
	 * 条件+分页
	 * */
	
	
	public ResultModel doUpdateD(CommonPage<JhySampleConsignD> cp)
	{
		ResultModel rm=new ResultModel();
		JhySampleConsignD  JhySamp  = new JhySampleConsignD();
		JhySampleConsignDItem JhySampItem = new JhySampleConsignDItem();
		
		try {
			JhySamp = cp.getObject();
			
			//JhySampleConsignD dd = this.getMapper(JhySampleConsignDMapper.class).GetChemBysql(cp.getObject().getSmpNo(), cp.getObject().getFreqCode());
			
			
			//String CONSIGN_NO = this.getMapper(JhySampleConsignDMapper.class).GetMaxCode();
			String Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(cp.getObject().getSmpNo());
			
			
			//JhySamp.setConsignNo(CONSIGN_NO);
			this.getMapper(JhySampleConsignDMapper.class).update(JhySamp);
			
			
			this.getMapper(JhySampleConsignDMapper.class).dodeleteDItem(cp.getObject().getSpecimenNo());
			
			this.getMapper(JhySampleConsignDMapper.class).doInsertDItem(cp.getObject().getSmpNo(), Seq,cp.getObject().getSpecimenNo());
			
			Seq = this.getMapper(JhySampleConsignDMapper.class).GetMaxSEQ(cp.getObject().getSmpNo());
			this.getMapper(JhySampleConsignDMapper.class).doInsertDItem2(cp.getObject().getSmpNo(), Seq,cp.getObject().getAllItemCode());

			
			rm.setState("200");
		} catch (Exception e) {
			// TODO: handle exception
			
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
		}
		
		return rm;
		
		
	}
	
	public ResultModel dodeleteDp(CommonPage<JhySampleConsignD> cp)
	{
		ResultModel rm=new ResultModel();
		try {
			
			String aa = cp.getObject().getSpecimenNo();
			this.getMapper(JhySampleConsignDMapper.class).dodeleteDp(aa);
			
			this.getMapper(JhySampleConsignDMapper.class).dodeleteDItem(cp.getObject().getSpecimenNo());
			rm.setState("200");
			
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
		}
		return rm;
		
	}
	
	public ResultModel doSendDp(CommonPage<JhySampleConsignD> cp)
	{
		ResultModel rm=new ResultModel();
		try {
			
			for(JhySampleConsignD aa : cp.getObjectList())
			{
				
			this.getMapper(JhySampleConsignDMapper.class).doSendDp(aa.getSpecimenNo());
			
			}
			rm.setState("200");
			
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
		}
		return rm;
		
	}
	
}
