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

import java.util.ArrayList;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.common.ReturnMsg;
import market.Qms.qcm.mapper.JhySampleConsignMMapper;
import market.Qms.qcm.service.JhySampleConsignMService;
import market.Qms.qcm.vo.JhySampleConsignM;
import market.Qms.qcm.vo.JhySampleROrd;

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

@RemoteService(path="JhySampleConsignMService")
public class JhySampleConsignMServiceImpl extends BaseServiceImpl<JhySampleConsignM, String> implements JhySampleConsignMService {

	@Override
	public ReturnMsg<List<JhySampleConsignM>> doQuerybySql(String SMP_NO, String HEAT_NO, String BATCH_NO,
			String CONTRACT_LINE_NO) {
		// TODO Auto-generated method stub
		ReturnMsg<List<JhySampleConsignM>> msg = new ReturnMsg<>();
		List<JhySampleConsignM> list = new ArrayList<>();
		try {
			list = this.getMapper(JhySampleConsignMMapper.class).doQuerybySql(SMP_NO, HEAT_NO, BATCH_NO, CONTRACT_LINE_NO);
			
			msg.setMessage("获取数据成功");
			msg.setSuccess(true);
			msg.setResult(list);
		} catch (Exception e) {
			msg.setSuccess(false);
			msg.setMessage(e.getMessage());
		}
		return msg;
	}
	
	
	/**
	 * 委托主表
	 * SQL实现
	 * 条件+分页
	 * */
	public ResultModel doQueryWebBySQL(CommonPage<JhySampleConsignM> cp)
	{
		ResultModel rm=new ResultModel();
		int pageSize=cp.getPageSize();
		int pageIndex=cp.getPageIndex();
		PageModel<JhySampleConsignM> pm = new PageModel<JhySampleConsignM>(pageIndex,pageSize);
		try
		{																										
		
			rm.setData(this.getMapper(JhySampleConsignMMapper.class).QuerybySql
					((pageIndex-1)*pageSize, (pageIndex-1)*pageSize+pageSize, cp.getStartTime(), cp.getEndTime(), cp.getObject().getSmpNo(), cp.getObject().getHeatNo(),cp.getObject().getBatchNo(),cp.getMemo1()));
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	/**
	 * 插入委托主表
	 * SQL实现
	 * 
	 * */
	
	@SuppressWarnings("unchecked")
	public  ReturnMsg<String> DoInsertJhy(CommonPage<JhySampleConsignM> cp)
	{
		
		ReturnMsg<String> msg = new ReturnMsg<>();
		JhySampleConsignM JhySamp = new JhySampleConsignM();
		JhySampleROrd JhyOrd = new JhySampleROrd();
		try {
			
			JhySamp = cp.getObject();
			String Jhy_no = this.getMapper(JhySampleConsignMMapper.class).GetMaxCode();

			JhySamp.setSmpNo(Jhy_no);
			
			this.getMapper(JhySampleConsignMMapper.class).insert(JhySamp);
			
			JhyOrd.setSmpNo(Jhy_no);
			JhyOrd.setBatchNo(cp.getObject().getBatchNo());
			JhyOrd.setCertInstCode(cp.getObject().getCertInstCode());
			JhyOrd.setCertInstName(cp.getObject().getCertInstName());
			JhyOrd.setContractLineNo(cp.getMemo1());
			JhyOrd.setHeatNo(cp.getObject().getHeatNo());
			JhyOrd.setIsview("0");
			JhyOrd.setJudgeMemo("");
			JhyOrd.setJudgeName("");
			JhyOrd.setJudgeResult("");
			
			//JhyOrd.setPicId(picId);
			JhyOrd.setSmpNo(cp.getObject().getSmpNo());
			JhyOrd.setSmpTypeCode(cp.getObject().getSmpTypeCode());
			JhyOrd.setSmpTypeName(cp.getObject().getSmpTypeName());
			
			this.getMapper(JhySampleConsignMMapper.class).doInsertOrd(JhyOrd);
			
			msg.setMessage("新增成功");
			msg.setSuccess(true);
			msg.setResult("200");
			
		} catch (Exception e) {
			// TODO: handle exception
			msg.setMessage(e.getMessage());
			msg.setSuccess(false);
			
		}
		return null;
		
	}
	
	/**
	 * 修改委托主表
	 * SQL实现
	 * 
	 * */
	
	@SuppressWarnings("unchecked")
	public ResultModel doUpdateJhy(CommonPage<JhySampleConsignM> cp)
	{
		ResultModel rm = new ResultModel();
		JhySampleConsignM JhySamp = new JhySampleConsignM();
		JhySampleROrd JhyOrd = new JhySampleROrd();
		
		try {
			
			JhySamp = cp.getObject();
			//String Jhy_no = this.getMapper(JhySampleConsignMMapper.class).GetMaxCode();

			//JhySamp.setSmpNo(Jhy_no);
			
			this.getMapper(JhySampleConsignMMapper.class).update(JhySamp);
			
			JhyOrd.setSmpNo(cp.getObject().getSmpNo());
			JhyOrd.setBatchNo(cp.getObject().getBatchNo());
			JhyOrd.setCertInstCode(cp.getObject().getCertInstCode());
			JhyOrd.setCertInstName(cp.getObject().getCertInstName());
			JhyOrd.setContractLineNo(cp.getMemo1());
			JhyOrd.setHeatNo(cp.getObject().getHeatNo());
			JhyOrd.setIsview("0");
			JhyOrd.setJudgeMemo("");
			JhyOrd.setJudgeName("");
			JhyOrd.setJudgeResult("");
			
			//JhyOrd.setPicId(picId);
			JhyOrd.setSmpNo(cp.getObject().getSmpNo());
			JhyOrd.setSmpTypeCode(cp.getObject().getSmpTypeCode());
			JhyOrd.setSmpTypeName(cp.getObject().getSmpTypeName());
			
			this.getMapper(JhySampleConsignMMapper.class).doUpdateOrd(JhyOrd);
			
			
			rm.setState("200");
			
		} catch (Exception e) {
			// TODO: handle exception
			
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
			e.printStackTrace();
		}
		return rm;
		
		
	}
	
	
	/**
	 * 删除委托主表
	 * SQL实现
	 * 
	 * */
	@SuppressWarnings("unchecked")
	public ResultModel doDeleJhy(CommonPage<JhySampleConsignM> cp)
	{
		ResultModel rm = new ResultModel();
		JhySampleConsignM Jhy = new JhySampleConsignM();
		try {
			Jhy.setSmpNo(cp.getObject().getSmpNo());
			String aa = cp.getObject().getSmpNo();
			this.getMapper(JhySampleConsignMMapper.class).dodeleteM(aa);
			this.getMapper(JhySampleConsignMMapper.class).dodeleteOrd(cp.getObject().getSmpNo(),cp.getMemo1());
			
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，关闭失败!");
		}
		return rm;

	}

}
