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

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 ComMscStdPhyMapper  extends GenericMapper<ComMscStdPhy, Object> {
	
	@Select("select nvl(max(t.index_seq),0)+1 from  com_msc_std_phy t where t.pic = #{pic}")  
	int getIndexNo(@Param("pic") String pic);

    /**
     * 获取元素个数
     * @param cic
     * @return
     */
	@Select("select  count(*) from COM_MSC_STD_PHY where pic = #{pic}")
	public Integer chemCode(@Param("pic") String pic);
	 
	@Update("UPDATE COM_MSC_STD_PHY SET GROUP_SEQ = NULL WHERE PIC = #{pic} AND INDEX_SEQ = #{index}")
	public void updatec(@Param("pic") String pic,@Param("index") Integer index);
	
	@Select("SELECT max(GROUP_SEQ) FROM COM_MSC_STD_PHY WHERE PIC = #{pic}")
	public String findmax(@Param("pic") String pic);
	
//	SELECT count(*) FROM COM_MSC_STD_PHY WHERE GROUP_SEQ != NULL AND pic = 'PICN000002'
			
	
			@Select("SELECT count(*) FROM COM_MSC_STD_PHY WHERE GROUP_SEQ IS NOT NULL AND pic = #{pic}")
			public Integer findnum(@Param("pic") String pic);
			
			@Update("UPDATE COM_MSC_STD_PHY SET DELETE_NAME = NULL,DELETE_TIME = NULL,VALIDFLAG=1 WHERE PIC = #{pic} AND INDEX_SEQ = #{index}")
			public void updateno(@Param("pic") String pic,@Param("index") Integer index);
			
			
			@Update("UPDATE COM_MSC_STD_PHY a SET a.validflag='0',a.DELETE_TIME=sysdate,a.DELETE_NAME=#{name}  WHERE PIC = #{pic}")
			public void updateZf(@Param("pic") String pic,@Param("name")String name);
			
			@Update("UPDATE COM_MSC_STD_PHY a SET a.validflag='1',a.DELETE_TIME=null,a.DELETE_NAME=null  WHERE PIC = #{pic}")
			public void updateHf(@Param("pic") String pic);

			@Select("SELECT count(*) FROM COM_MSC_STD_PHY t,com_msc_std_pic p WHERE t.GROUP_SEQ IS NOT NULL AND t.pic=p.pic and p.psc= #{psc}")
			int findnumpsc(@Param("psc")String psc);
			@Select("SELECT max(to_number(t.GROUP_SEQ)) FROM COM_MSC_STD_PHY t,com_msc_std_pic p WHERE t.GROUP_SEQ IS NOT NULL AND t.pic=p.pic and p.psc= #{psc}")
			String findmaxpsc(@Param("psc")String psc);
}