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

import market.Com.mapper.ComBaseSampleMapper;
import market.Com.vo.ComBaseSample;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.metallurgy.mapper.ComMscCicSampleMapper;
import market.Qms.metallurgy.service.ComMscCicSampleService;
import market.Qms.metallurgy.vo.ComMscCicSample;

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="ComMscCicSampleService")
public class ComMscCicSampleServiceImpl extends BaseServiceImpl<ComMscCicSample,Object> implements ComMscCicSampleService {


	public ResultModel doQuery(CommonPage<ComMscCicSample> cb) 
	{
		ResultModel rm = new ResultModel();
		int pageIndex = cb.getPageIndex();
		int pageSize = cb.getPageSize();
		PageModel<ComMscCicSample> pm = new PageModel<ComMscCicSample>(pageIndex,pageSize);
		try {
                ComMscCicSample object = cb.getObject();
                ComMscCicSample c = new ComMscCicSample();
                c.setCic(object.getCic());
                List<ComMscCicSample> list = this.getMapper(ComMscCicSampleMapper.class).find(c, 0, 0);
			pm.setRows(list);
            pm.setTotal(list.size());      			
			rm.setData(pm);
			rm.setState("200");
			rm.setMsgInfo("查询成功！");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			e.printStackTrace();
		}
		return rm;
	}
	
	public ResultModel doSaveCic(CommonPage<ComMscCicSample> sum)
	{
		
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		ResultModel rm = new ResultModel();
		Date date = new Date();
		try{
		List<ComMscCicSample> list = sum.getObjectList();
		if(list != null && list.size() > 0)
		{
			ComMscCicSample cicSample = list.get(0);
			this.getMapper(ComMscCicSampleMapper.class).doDelete(cicSample.getCic());
		for(ComMscCicSample c:list)
		{
			c.setCreate_name(userName);
			c.setCreate_time(date);
			this.getMapper(ComMscCicSampleMapper.class).insert(c);
		}
			
		}	
		rm.setMsgInfo("关联成功！");
		rm.setState("200");
	} catch (Exception ex) {
		rm.setState("500");
		rm.setMsgInfo("关联失败!");
		ex.printStackTrace();
	}
		return rm;
	}

	public ResultModel doQuerySample(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(ComBaseSampleMapper.class).findpop(sample.getSmp_type());
			pm.setRows(list);
			pm.setTotal(list.size());
			rm.setData(pm);
			rm.setMsgInfo("查询成功！");
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("服务器内部异常!");
			e.printStackTrace();
		}
		
		return rm;
		
	}
	
	
}
