/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-18
 * 描述            ：材质标准取样要求表(取样码索引号关联)
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.metallurgy.impl;
import java.util.Date;
import java.util.List;

import market.Com.vo.ComBaseSample;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.metallurgy.mapper.ComMscPhySampleMapper;
import market.Qms.metallurgy.service.ComMscPhySampleService;
import market.Qms.metallurgy.vo.ComMscPhySample;

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

@RemoteService(path="ComMscPhySampleService")
public class ComMscPhySampleServiceImpl extends BaseServiceImpl<ComMscPhySample,Object> implements ComMscPhySampleService {
	public ResultModel doQueryComMscStdDetection(CommonPage<ComMscPhySample> cb) {
		ResultModel rm = new ResultModel();
		int pageIndex = cb.getPageIndex();
		int pageSize = cb.getPageSize();
		PageModel<ComMscPhySample> pm = new PageModel<ComMscPhySample>(pageIndex, pageSize);
		try{
		
		ComMscPhySample sample = cb.getObject();
		ComMscPhySample cp = new ComMscPhySample();
		cp.setPic(sample.getPic());
		cp.setPhy_code_m(sample.getPhy_code_m());
		cp.setSample_key(sample.getSample_key());
		List<ComMscPhySample> list = this.getMapper(ComMscPhySampleMapper.class).find(cp, 0, 0);
		pm.setRows(list);
		pm.setTotal(list.size());
		rm.setData(pm);
		rm.setMsgInfo("查询成功！");
		rm.setState("200");
		
	} catch (Exception ex) {
		rm.setState("500");
		rm.setMsgInfo("查询失败!");
		ex.printStackTrace();
	}
		return rm;
		
	}
	
	public ResultModel doQueryComBaseSample(CommonPage<ComBaseSample> cb) {
		ResultModel rm = new ResultModel();
		int pageIndex = cb.getPageIndex();
		int pageSize = cb.getPageSize();
		PageModel<ComBaseSample> pm = new PageModel<ComBaseSample>(pageIndex, pageSize);
		ComBaseSample sample = cb.getObject();
	try{
		List<ComBaseSample> list = this.getMapper(ComMscPhySampleMapper.class).GexList(sample.getStd_code(),
				sample.getSteel_code(), sample.getProd_code(), sample.getPhy_code_m());
		pm.setRows(list);
		pm.setTotal(list.size());
		rm.setMsgInfo("查询成功！");
		rm.setData(pm);
		rm.setState("200");
	} catch (Exception ex) {
		rm.setState("500");
		rm.setMsgInfo("查询失败!");
		ex.printStackTrace();
	}
		return rm;
	}
	public ResultModel doSave(List<ComMscPhySample> coms) 
	{
		ResultModel rm = new ResultModel();
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date date = new Date();
		try {
			if (!coms.isEmpty()) {

				

				this.getMapper(ComMscPhySampleMapper.class).deletec(coms.get(0).getPic());
				
				for (ComMscPhySample com : coms) {
					com.setCreate_name(userName);
					com.setCreate_time(date);
					this.getMapper(ComMscPhySampleMapper.class).insert(com);
				}
				rm.setMsgInfo("关联成功！");
				rm.setState("200");
			}
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("关联失败!");
			ex.printStackTrace();
		}
		return rm;

	}
}
