package market.Qms.metallurgy.mapper;
import market.Qms.metallurgy.vo.ComMscStdSpecC;

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 ComMscStdSpecCMapper extends GenericMapper<ComMscStdSpecC, Object> {

	@Select("select nvl(max(t.index_seq),0)+1 from  com_msc_std_spec_c t where t.sic = #{sic}")  
	Integer getIndexNo(@Param("sic") String sic);
    /**
     * 获取元素个数
     * @param cic
     * @return
     */
	@Select("select  nvl(count(c.sic),0) count from   com_msc_std_spec b  left join com_msc_std_spec_c c on b.sic = c.sic where b.sic = #{sic} and c.validflag ='1'")
	public Integer chemCode(@Param("sic") String sic);
	
	public Integer chem(String param);
	
	@Update("UPDATE com_msc_std_spec_c SET GROUP_SEQ = NULL WHERE SIC = #{sic} AND INDEX_SEQ = #{index}")
	public void updatec(@Param("sic") String sic,@Param("index") Integer index);
	@Select("SELECT max(GROUP_SEQ) FROM com_msc_std_spec_C WHERE SIC = #{sic}")
	public String findmax(@Param("sic") String sic);
	
	
	@Update("UPDATE com_msc_std_spec_c SET DELETE_NAME=NULL,DELETE_TIME=NULL,VALIDFLAG=1 WHERE SIC = #{sic} AND INDEX_SEQ = #{index}")
	public void updatef(@Param("sic") String sic,@Param("index") Integer index);
	
	@Update("UPDATE com_msc_std_spec_c SET DELETE_NAME=#{name},DELETE_TIME=sysdate,VALIDFLAG=1 WHERE SIC = #{sic}")
	public void updateSicZf(@Param("sic") String sic,@Param("name")String name);
	
	@Update("UPDATE com_msc_std_spec_c SET DELETE_NAME=NULL,DELETE_TIME=NULL,VALIDFLAG=1 WHERE SIC = #{sic}")
	public void updateSicHf(@Param("sic") String sic);
	
	@Select("SELECT count(*) FROM com_msc_std_spec_C WHERE GROUP_SEQ IS NOT NULL AND SIC = #{sic}")
	public Integer findnum(@Param("sic") String sic);
	
	@Select("SELECT count(*) FROM com_msc_std_spec_C t,com_msc_std_spec c WHERE t.GROUP_SEQ IS NOT NULL AND t.sic=c.sic and c.psc=#{psc}")
	int findnumpsc(@Param("psc")String psc);
	
	@Select("SELECT max(to_number(t.GROUP_SEQ)) FROM com_msc_std_spec_C t,com_msc_std_spec c WHERE t.GROUP_SEQ IS NOT NULL AND t.sic=c.sic and c.psc=#{psc}")
	String findmaxpsc(@Param("psc")String psc);
	
}