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

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 ComMscStdDetectionCMapper extends GenericMapper<ComMscStdDetectionC, Object> {
	   
		@Select("select nvl(max(t.index_seq),0)+1 from  com_msc_std_detection_c t where t.dic = #{dic}")  
		int getIndexNo(@Param("dic") String dic);
	    /**
	     * 获取元素个数
	     * @param cic
	     * @return
	     */
		@Select("select  nvl(count(c.dic),0) count from  com_msc_std_detection b  left join com_msc_std_detection_c c on b.dic = c.dic where b.dic = #{dic} and c.validflag ='1'")
		public Integer chemCode(@Param("dic") String dic);
		
		@Update("UPDATE COM_MSC_STD_DETECTION_C SET VALIDFLAG =1,DELETE_NAME = NULL,DELETE_TIME = NULL WHERE dic =#{dic} AND INDEX_SEQ =#{index}")
		public void updatec(@Param("dic") String dic,@Param("index") Integer index);
		
		@Update("UPDATE com_msc_std_detection_c SET GROUP_SEQ = NULL WHERE DIC = #{dic} AND INDEX_SEQ = #{index}")
		public void updatecd(@Param("dic") String dic,@Param("index") Integer index);
		@Select("SELECT max(GROUP_SEQ) FROM com_msc_std_detection_c WHERE DIC = #{dic}")
		public String findmax(@Param("dic") String dic);
		@Select("SELECT count(*) FROM com_msc_std_detection_c WHERE GROUP_SEQ IS NOT NULL AND DIC = #{dic}")
		public Integer findnum(@Param("dic") String dic);
		
		@Update("UPDATE COM_MSC_STD_DETECTION_C SET VALIDFLAG =0,DELETE_NAME = #{name},DELETE_TIME = sysdate WHERE dic =#{dic}")
		public void updateDicZf(@Param("dic") String dic,@Param("name") String name);
		
		@Update("UPDATE COM_MSC_STD_DETECTION_C SET VALIDFLAG =0,DELETE_NAME = NULL,DELETE_TIME = NULL WHERE dic =#{dic}")
		public void updateDicHf(@Param("dic") String dic);
		@Select("SELECT count(*) FROM com_msc_std_detection_c t, com_msc_std_detection d WHERE t.GROUP_SEQ IS NOT NULL AND t.dic=d.dic and d.psc= #{psc}")
		int findnumpsc(@Param("psc")String psc);
		@Select("SELECT max(to_number(t.GROUP_SEQ)) FROM com_msc_std_detection_c t, com_msc_std_detection d WHERE t.GROUP_SEQ IS NOT NULL AND t.dic=d.dic and d.psc= #{psc}")
		String findmaxpsc(@Param("psc")String psc);
		
}