package market.Qms.qcm.mapper;
import java.util.List;

import market.Qms.qcm.vo.QcmZbsBill;
import market.Qms.qcm.vo.QcmZbsDataOrd;

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 QcmZbsBillMapper extends GenericMapper<QcmZbsBill,Object> {

	List<QcmZbsBill> findByGroup(String bill_no, String contract_no, String starTime, String endTime, String data_sources);

	List<QcmZbsBill> findByHead(String bill_no, String steel_name, String prod_code, String delivery_state_code,
			String contract_no, String car_no, String reciver_unit_no, String cut_edge_type_no,
			String fixed_length_type_no);

	List<QcmZbsBill> findByAllCondition(String bill_no, String steel_name, String prod_code, String delivery_state_code,
			String contract_no, String car_no, String reciver_unit_no, String cut_edge_type_no,
			String fixed_length_type_no);

	List<QcmZbsBill> findByBatch(String bill_no, String steel_name, String prod_code, String delivery_state_code,
			String contract_no, String car_no, String reciver_unit_no, String cut_edge_type_no,
			String fixed_length_type_no);

	List<QcmZbsBill> findByLength(String bill_no, String steel_name, String prod_code, String delivery_state_code,
			String contract_no, String car_no, String reciver_unit_no, String cut_edge_type_no,
			String fixed_length_type_no);

	List<QcmZbsBill> findByWidth(String bill_no, String steel_name, String prod_code, String delivery_state_code,
			String contract_no, String car_no, String reciver_unit_no, String cut_edge_type_no,
			String fixed_length_type_no);

	void updateConditon(String deltail_no, String train_no, String contract_no, String prod_code, String std_code,
			String steel_code, String steel_name, String reciver_unit_code, String order_unit_code);

	void updateConditonSure(String bill_no, String car_no, String contract_no, String prod_code, String std_code,
			String steel_code, String steel_name, String reciver_unit_no, String order_unit_no);

	List<QcmZbsBill> findByNull(String bill_no, String steel_name, String prod_code, String delivery_state_code,
			String contract_no, String car_no, String reciver_unit_no, String cut_edge_type_no,
			String fixed_length_type_no);

	int findCount(String design_key);

	List<QcmZbsBill> findByAllBatch(String bill_no, String prod_code, String std_code, String reciver_unit_no,
			String delivery_state_code, String contract_no, String order_unit_no, String org_code, String batch_no,
			String thick, String width, String length, String string, String string2);

	List<QcmZbsBill> findByBatchLength(String bill_no, String prod_code, String std_code, String reciver_unit_no,
			String delivery_state_code, String contract_no, String order_unit_no, String org_code, String batch_no,
			String thick, String length, String string, String string2);

	List<QcmZbsBill> findByBatchWidth(String bill_no, String prod_code, String std_code, String reciver_unit_no,
			String delivery_state_code, String contract_no, String order_unit_no, String org_code, String batch_no,
			String thick, String width, String string, String string2);

	List<QcmZbsBill> findByBatchThick(String bill_no, String prod_code, String std_code, String reciver_unit_no,
			String delivery_state_code, String contract_no, String order_unit_no, String org_code, String batch_no,
			String thick, String string, String string2);

	List<QcmZbsBill> findHead(String bill_no, String contract_no, String starTime, String endTime, String data_sources,
			Integer pageIndex, Integer pageSize, String steel_name, String order_unit_name, String object_nos, String contructNos);

	List<QcmZbsBill> findNoCondition(QcmZbsDataOrd ord);

	List<QcmZbsBill> findGroupAll(QcmZbsDataOrd ord);

	List<QcmZbsBill> findByGroupBatch(QcmZbsBill b);

	@Update("update QCM_ZBS_BILL set IS_CREATE_BOOK='1' where BILL_NO=#{bill_no} and OBJECT_NO=#{object_no}")
	void updateCreatBook(@Param("bill_no")String bill_no, @Param("object_no")String object_no);

	@Select("SELECT DISTINCT(T.BILL_NO) || '#' || CONTRACT_NO FROM QCM_ZBS_BILL  T WHERE T.OBJECT_NO LIKE '%${object_no}%'")
	List<String> findBills(@Param("object_no")String object_no);
	
	@Select("select nvl(sum(count(distinct t.bill_no)),0) from QCM_ZBS_BILL t "
			+ "where t.is_create_book = '0' and t.data_sources = '1' ${condition}"
			+ "group by t.bill_no, t.prod_code, t.prod_name, t.std_code, t.std_name, t.steel_code, t.steel_name,"
			+ "t.car_no,t.contract_no, t.reciver_unit_no, t.reciver_unit_name, t.delivery_state_code, t.delivery_state_desc,"
			+ "t.order_unit_no,t.order_unit_name, t.org_code, t.org_name")
	public int findHeadCount(@Param("condition")String condition);
	
	@Select("${sql}")
	public int doQueryIsExistsTOrL(@Param("sql")String sql);
	
	@Select("${sql}")
	public int getIsBC(@Param("sql")String sql);
}
