/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2018.2.5
 * 描述               :        			取样码与钢级对应关系
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/
package market.Com.impl;

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

import market.Com.mapper.ComBaseSampleRSteelMapper;
import market.Com.service.ComBaseSampleRSteelService;
import market.Com.vo.ComBaseSampleRSteel;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="ComBaseSampleRSteelService")
public class ComBaseSampleRSteelServiceImpl extends BaseServiceImpl<ComBaseSampleRSteel,Object> implements ComBaseSampleRSteelService {

	/**
	 * 保存 新增失败则回滚之前删除的
	 * @param sum
	 * @return
	 * @throws ParseException 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddRSteel(CommonPage<ComBaseSampleRSteel> sum)throws ParseException{
		ResultModel rm =new ResultModel();
		ComBaseSampleRSteel steel =sum.getObject();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSS");
		Date time =null;
		time= sdf.parse(sdf.format(new Date()));
		steel.setCreate_time(time);
		steel.setValidflag("1");
		ComBaseSampleRSteel Rsteel =this.getMapper(ComBaseSampleRSteelMapper.class).findById(steel.getSmp_index());
		if (Rsteel!=null) {
			this.getMapper(ComBaseSampleRSteelMapper.class).delete(Rsteel.getSmp_index());
		}
		this.getMapper(ComBaseSampleRSteelMapper.class).insert(steel);
		rm.setState("200");
		return rm;
	}

}
