/***文档注释***********************************************
 * 作者               :                   龙文航
 * 创建日期      :                   2017.12.09
 * 描述               :                   原料库管理 成分维护
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/
package market.Lms.Warehouse.impl;

import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmChemMapper;
import market.Lms.Warehouse.service.YdmChemService;
import market.Lms.Warehouse.vo.YdmChem;

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

@RemoteService(path="YdmChemService")
public class YdmChemServiceImpl extends BaseServiceImpl<YdmChem,Object> implements YdmChemService {
	/**
	 * 原料库管理 成分维护 判断是否维护
	 * */
	public ResultModel doJudge(CommonPage<YdmChem> cp)
	{
		ResultModel rm=new ResultModel();
		try
		{
			YdmChem yc=cp.getObject();
			if(yc!=null)
			{
				if(yc.getHeatno()!=null&&yc.getHeatno()!="")
				{
					List<YdmChem> list=this.getMapper(YdmChemMapper.class).find(yc, 0, 0);
					if(list!=null&&list.size()>0)
					{
						rm.setData(list);
						rm.setState("200");
					}
					else 
					{
						rm.setState("500");
						rm.setMsgInfo("未维护该炉号的成分!");
					}
				}
			}
			else 
			{
				rm.setState("500");
				rm.setMsgInfo("传入的数据为空!");
			}
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，判断失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 成分维护 保存
	 * 传入炉号
	 * */
	public ResultModel doSave(CommonPage<YdmChem> cp)
	{
		ResultModel rm=new ResultModel();
		String username=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try
		{
			YdmChem yc=cp.getObject();
			yc.setCreate_opr(username);
			yc.setCreate_time(new Date());
			yc.setInspect_time(String.valueOf(new Date()));
			if(yc.getHeatno()!=null&&yc.getHeatno()!="")
			{
				yc.setHeatno(yc.getHeatno());
				//删除对应炉号的成分实绩
				this.getMapper(YdmChemMapper.class).doDeleteByHeatno(yc.getHeatno());
			}
			if(yc.getC()!=null&&yc.getC()!="")
			{
				yc.setChem_code("C");
				yc.setChem_value(Double.valueOf(yc.getC()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getSi()!=null&&yc.getSi()!="")
			{
				yc.setChem_code("SI");
				yc.setChem_value(Double.valueOf(yc.getSi()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getMn()!=null&&yc.getMn()!="")
			{
				yc.setChem_code("MN");
				yc.setChem_value(Double.valueOf(yc.getMn()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getP()!=null&&yc.getP()!="")
			{
				yc.setChem_code("P");
				yc.setChem_value(Double.valueOf(yc.getP()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getS()!=null&&yc.getS()!="")
			{
				yc.setChem_code("S");
				yc.setChem_value(Double.valueOf(yc.getS()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getNi()!=null&&yc.getNi()!="")
			{
				yc.setChem_code("NI");
				yc.setChem_value(Double.valueOf(yc.getNi()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getCr()!=null&&yc.getCr()!="")
			{
				yc.setChem_code("CR");
				yc.setChem_value(Double.valueOf(yc.getCr()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getCu()!=null&&yc.getCu()!="")
			{
				yc.setChem_code("CU");
				yc.setChem_value(Double.valueOf(yc.getCu()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getAsn()!=null&&yc.getAsn()!="")
			{
				yc.setChem_code("ASN");
				yc.setChem_value(Double.valueOf(yc.getAsn()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getTi()!=null&&yc.getTi()!="")
			{
				yc.setChem_code("TI");
				yc.setChem_value(Double.valueOf(yc.getTi()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getV()!=null&&yc.getV()!="")
			{
				yc.setChem_code("V");
				yc.setChem_value(Double.valueOf(yc.getV()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getMo()!=null&&yc.getMo()!="")
			{
				yc.setChem_code("MO");
				yc.setChem_value(Double.valueOf(yc.getMo()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getB()!=null&&yc.getB()!="")
			{
				yc.setChem_code("B");
				yc.setChem_value(Double.valueOf(yc.getB()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getW()!=null&&yc.getW()!="")
			{
				yc.setChem_code("W");
				yc.setChem_value(Double.valueOf(yc.getW()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getAl()!=null&&yc.getAl()!="")
			{
				yc.setChem_code("AL");
				yc.setChem_value(Double.valueOf(yc.getAl()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getZn()!=null&&yc.getZn()!="")
			{
				yc.setChem_code("ZN");
				yc.setChem_value(Double.valueOf(yc.getZn()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getPb()!=null&&yc.getPb()!="")
			{
				yc.setChem_code("PB");
				yc.setChem_value(Double.valueOf(yc.getPb()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getSn()!=null&&yc.getSn()!="")
			{
				yc.setChem_code("SN");
				yc.setChem_value(Double.valueOf(yc.getSn()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getCa()!=null&&yc.getCa()!="")
			{
				yc.setChem_code("CA");
				yc.setChem_value(Double.valueOf(yc.getCa()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getLa()!=null&&yc.getLa()!="")
			{
				yc.setChem_code("LA");
				yc.setChem_value(Double.valueOf(yc.getLa()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getSb()!=null&&yc.getSb()!="")
			{
				yc.setChem_code("SB");
				yc.setChem_value(Double.valueOf(yc.getSb()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getCe()!=null&&yc.getCe()!="")
			{
				yc.setChem_code("CE");
				yc.setChem_value(Double.valueOf(yc.getCe()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getSe()!=null&&yc.getSe()!="")
			{
				yc.setChem_code("SE");
				yc.setChem_value(Double.valueOf(yc.getSe()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getMg()!=null&&yc.getMg()!="")
			{
				yc.setChem_code("MG");
				yc.setChem_value(Double.valueOf(yc.getMg()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			if(yc.getNb()!=null&&yc.getNb()!="")
			{
				yc.setChem_code("NB");
				yc.setChem_value(Double.valueOf(yc.getNb()));
				this.getMapper(YdmChemMapper.class).insert(yc);
			}
			rm.setState("200");
		}
		catch(Exception ex)
		{
			rm.setState("500");
			rm.setMsgInfo("服务端异常，保存失败!");
			ex.printStackTrace();
		}
		return rm;
	}
}
