/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.10.24
 * 描述               :        			成分要求表
 * 注意事项      :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/
package market.Slm.ContractManagement.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.ContractManagement.mapper.SlmCustAlphaChemMapper;
import market.Slm.ContractManagement.service.SlmCustAlphaChemService;
import market.Slm.ContractManagement.vo.SlmCustAlphaChem;

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

@RemoteService(path="SlmCustAlphaChemService")
public class SlmCustAlphaChemServiceImpl extends BaseServiceImpl<SlmCustAlphaChem,Object> implements SlmCustAlphaChemService {

	/**
	 * 成分要求 - 新增
	 * */
	public ResultModel doAddWeb(CommonPage<SlmCustAlphaChem> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlphaChem chem=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			String seq=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
			chem.setChem_seq(seq);
			chem.setCreate_no(userId);
			chem.setCreate_name(userName);
			chem.setCreate_time(new Date());
			if(chem.getValidflag()==null)
				chem.setValidflag("1");
			this.getMapper(SlmCustAlphaChemMapper.class).insert(chem);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("新增失败!"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 成分要求 - 编辑
	 * */
	public ResultModel doUpdateWeb(CommonPage<SlmCustAlphaChem> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlphaChem chem=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			chem.setUpdate_no(userId);
			chem.setUpdate_name(userName);
			chem.setUpdate_time(new Date());
			this.getMapper(SlmCustAlphaChemMapper.class).update(chem);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("编辑失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 成分要求 - 详情
	 * */
	public ResultModel doQueryDetailWeb(CommonPage<SlmCustAlphaChem> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlphaChem chem=sum.getObject();
		try{
			chem=this.getMapper(SlmCustAlphaChemMapper.class).findById(chem.getChem_seq());
			rm.setState("200");
			rm.setData(chem);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
}
