/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2019-02-23
 * 描述            ：质保书材质展示项配置表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.qcm.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.qcm.mapper.QcmZbsTmplCicMapper;
import market.Qms.qcm.mapper.QcmZbsTmplPicMapper;
import market.Qms.qcm.service.QcmZbsTmplPicService;
import market.Qms.qcm.vo.QcmZbsTmplPic;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="QcmZbsTmplPicService")
public class QcmZbsTmplPicServiceImpl extends BaseServiceImpl<QcmZbsTmplPic,Object> implements QcmZbsTmplPicService {



	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel addPicItem(CommonPage<QcmZbsTmplPic> oic) throws Exception{
		
		ResultModel rm=new ResultModel();
		String userName = this.getSession().getAttribute(HomeService.SESSION_USER_NAME).toString();
		try {
			
			if (oic==null) {
				rm.setState("500");
				rm.setMsgInfo("请传入参数！");
				return rm;
				
			}
			String tmpl_cret_no=oic.getMemo1();
			if (tmpl_cret_no==null || "".equals(tmpl_cret_no)) {
				rm.setState("500");
				rm.setMsgInfo("请传入方案编号！");
				return rm;
				
			}
			
			this.getMapper(QcmZbsTmplPicMapper.class).deleteByNo(tmpl_cret_no);
			List<QcmZbsTmplPic> pics=oic.getObjectList();
			for (QcmZbsTmplPic qcmZbsTmplPic : pics) {
				qcmZbsTmplPic.setCreate_time(new Date());
				qcmZbsTmplPic.setCreate_name(userName);
				this.getMapper(QcmZbsTmplPicMapper.class).insert(qcmZbsTmplPic);
			}
			
		} catch (Exception e) {
			throw new Exception("添加成分模板失败！");
		}
		
		
		
		
		return rm;
		
		
	}
	
	
	/**
	 * 查询成分方法
	 */
	public ResultModel getPicItem(CommonPage<QcmZbsTmplPic> oic){
		ResultModel rm=new ResultModel();
		if (oic==null) {
			rm.setState("500");
			rm.setMsgInfo("请传入参数！");
			return rm;
			
		}
		List<QcmZbsTmplPic> pics=new ArrayList<QcmZbsTmplPic>();
		if (oic.getMemo1()!=null && !"".equals(oic.getMemo1())) {
			pics=this.getMapper(QcmZbsTmplPicMapper.class).findWithCondition(null, "TMPL_CRET_NO='"+oic.getMemo1()+"'", null, 0, 0);
		}
		
		
		rm.setState("200");
		rm.setData(pics);
		
		return rm;
	}
	


	/**
	 * 查询材质项目
	 */

	public ResultModel getPhy(){
		ResultModel rm=new ResultModel();
		List<HashMap>  phys=this.getMapper(QcmZbsTmplCicMapper.class).findAll();
		
		rm.setData(phys);
		rm.setState("200");
		return rm;
		
	}
	
	
	




}
