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

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.qcm.mapper.QcmZbsTmplCicMapper;
import market.Qms.qcm.service.QcmZbsTmplCicService;
import market.Qms.qcm.vo.QcmZbsTmplCic;

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="QcmZbsTmplCicService")
public class QcmZbsTmplCicServiceImpl extends BaseServiceImpl<QcmZbsTmplCic,Object> implements QcmZbsTmplCicService {


	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel addCicItem(CommonPage<QcmZbsTmplCic> 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(QcmZbsTmplCicMapper.class).deleteByNo(tmpl_cret_no);
			List<QcmZbsTmplCic> cics=oic.getObjectList();
			for (QcmZbsTmplCic qcmZbsTmplCic : cics) {
				qcmZbsTmplCic.setCreate_time(new Date());
				qcmZbsTmplCic.setCreate_name(userName);
				this.getMapper(QcmZbsTmplCicMapper.class).insert(qcmZbsTmplCic);
			}
			
		} catch (Exception e) {
			throw new Exception("添加成分模板失败！");
		}
		
		
		
		
		return rm;
		
		
	}
	
	
	/**
	 * 查询成分方法
	 */
	public ResultModel getCicItem(CommonPage<QcmZbsTmplCic> oic){
		ResultModel rm=new ResultModel();
		if (oic==null) {
			rm.setState("500");
			rm.setMsgInfo("请传入参数！");
			return rm;
			
		}
		List<QcmZbsTmplCic> cics=new ArrayList<QcmZbsTmplCic>();
		if (oic.getMemo1()!=null && !"".equals(oic.getMemo1())) {
			cics=this.getMapper(QcmZbsTmplCicMapper.class).findWithCondition(null, "TMPL_CRET_NO='"+oic.getMemo1()+"'", null, 0, 0);
		}
		
		
		rm.setState("200");
		rm.setData(cics);
		
		return rm;
	}
	








}
