package market.Qms.metallurgy.mapper;


import java.util.List;

import market.Qms.metallurgy.vo.ComMscStdChem;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hnshituo.orm.GenericMapper;
public interface ComMscStdChemMapper extends  GenericMapper<ComMscStdChem, String> {
    
	@Select("select nvl(max(t.index_seq),0)+1 from  com_msc_std_chem t where t.cic = #{cic}")  
	int getIndexNo(@Param("cic") String cic);
    /**
     * 获取元素个数
     * @param cic
     * @return
     */
	@Select("select  nvl(count(c.chem_code),0) count from   com_msc_std_cic b  left join com_msc_std_chem c on b.cic = c.cic where b.cic = #{cic} and c.validflag ='1'")
	public Integer chemCode(@Param("cic") String cic);
	
	@Select("SELECT count(*) FROM COM_MSC_STD_CHEM WHERE CIC != #{cic} AND INDEX_SEQ != #{index} AND CHEM_NAME = #{name}")
	public Integer findvalid(@Param("cic") String cic,@Param("index") Integer index,@Param("name") String name);
	
	@Update("UPDATE COM_MSC_STD_CHEM SET DELETE_NAME=NULL,DELETE_TIME=NULL,VALIDFLAG=1 WHERE CIC = #{cic} AND INDEX_SEQ = #{index}")
	public void updatec(@Param("cic") String cic,@Param("index") Integer index);
	
	@Select("select max(index_seq+1) from COM_MSC_STD_CHEM where cic=#{cic}")
	public String GetMaxIndexSeq(@Param("cic")String cic);
	
	@Update("UPDATE COM_MSC_STD_CHEM SET DELETE_NAME=#{name},DELETE_TIME=sysdate,VALIDFLAG=0 WHERE CIC = #{cic}")
	public void updatecicZf(@Param("cic")String cic,@Param("name")String name);
	
	@Update("UPDATE COM_MSC_STD_CHEM SET DELETE_NAME=NULL,DELETE_TIME=NULL,VALIDFLAG=1 WHERE CIC = #{cic}")
	public void updatecicHf(@Param("cic") String cic);
	
	@Select("SELECT T.PLINE_CODE, T.PLINE_NAME FROM COM_BASE_PLINE T WHERE T.VALIDFLAG = '1' AND T.IS_DPS = '1'")
	List<ComMscStdChem> findChemPline();
	
}