package market.Slm.OrderManagement.mapper;

import java.util.HashMap;
import java.util.List;

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

import market.Slm.DeliveryManagement.vo.SlmLadingBillHeat;
import market.Slm.OrderManagement.vo.SlmOrderInfo;

import com.hnshituo.orm.GenericMapper;

@SuppressWarnings("rawtypes")
public interface SlmOrderInfoMapper extends GenericMapper<SlmOrderInfo,Object> {

	String doQueryMax(String contractLineNo);
	
	/**
	 * 计划管理--订单接收--查询订单信息
	 * */
	List<SlmOrderInfo> doOrderQueryWeb(SlmOrderInfo order, String sWhere);

	void doUpdate(SlmOrderInfo order);

	void doUpdateFlag(SlmOrderInfo soiu);

	void doEnable(SlmOrderInfo order);

	void doDelete(SlmOrderInfo order);

	List<SlmOrderInfo> doQuery(SlmOrderInfo order, String memo1, String memo2,
			String startTime, String endTime, String startTime2,
			String endTime2, int i, int j, String flags);

	int doQueryCount(SlmOrderInfo order, String customer_no,
			String txt_contract_no, String startTime, String endTime,
			String startTime2, String endTime2, String flags);

	List<SlmOrderInfo> doQueryForBill(SlmOrderInfo order, String order_no_sum, int i, int j);

	int doQueryForBillCount(SlmOrderInfo order,String order_no_sum);

	List<SlmOrderInfo> doQueryTrack(SlmOrderInfo order, String startTime,String endTime);

	List<SlmOrderInfo> doQueryYdm();

	List<SlmOrderInfo> doQueryForTranBill(SlmLadingBillHeat heat);

	int doQueryForTranBillCount(SlmLadingBillHeat heat);
	
	List<SlmOrderInfo> doQuerySlmOrderInfoByOrderno(String swhere);
	
	List<HashMap> doQueryCLByOrderno(String orderno);
	
	List<HashMap> doQuerySxDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryThDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryZjDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryPzDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryFtDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryKpDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryYlDetailByOrderno(String orderno,String memo);
	List<HashMap> doQueryKcDetailByOrderno(String orderno,String memo,String machine_name);
	//订单进程跟踪弹框
	Double doQueryOrderWeight3(String order,String status);
	Double doQuerySxWeight1(String orderno,String status);//酸洗
	Double doQuerySxWeight2(String orderno,String status);
	Double doQuerySxWeight3(String orderno,String status);
	Double doQueryThWeight1(String orderno,String status);//退火
	Double doQueryThWeight2(String orderno,String status);
	Double doQueryThWeight3(String orderno,String status);
	Double doQueryPzWeight1(String orderno,String status);//平整
	Double doQueryPzWeight2(String orderno,String status);
	Double doQueryPzWeight3(String orderno,String status);
	Double doQueryFtWeight1(String orderno,String status);//分条
	Double doQueryFtWeight2(String orderno,String status);
	Double doQueryFtWeight3(String orderno,String status);
	Double doQueryKpWeight1(String orderno,String status);//开平
	Double doQueryKpWeight2(String orderno,String status);
	Double doQueryKpWeight3(String orderno,String status);
	Double doQueryZjWeight1(String orderno,String status);//轧机
	Double doQueryZjWeight2(String orderno,String status);
	Double doQueryZjWeight3(String orderno,String status);
	Double doQueryKcWeight1(String orderno,String machine_name);//库存
	Double doQueryKcWeight2(String orderno,String machine_name);
	Double doQueryKcWeight3(String orderno,String machine_name);
	
	// 订单：入库后到编制之前的量：下一道工序酸洗工序
	Double doQuerySxWeightOther(String orderno);
	// 订单：入库后到编制之前的量：下一道工序退火工序
	Double doQueryThWeightOther(String orderno);
	// 订单：入库后到编制之前的量：下一道工序平整工序
	Double doQueryPzWeightOther(String orderno);
	// 订单：入库后到编制之前的量：下一道工序开平工序
	Double doQueryKpWeightOther(String orderno);
	// 订单：入库后到编制之前的量：下一道工序分条工序
	Double doQueryFtWeightOther(String orderno);
	// 订单：入库后到编制之前的量：下一道工序冷轧工序
	Double doQueryZjWeightOther(String orderno);
	
	@Select("select distinct soi.process,soi.order_no,soi.deliver_date from spm_delivery t "
			+ "left join slm_lading_bill_heat slbh on t.deliveryno = slbh.bill_no "
			+ "left join slm_lading_bill_detail d on t.deliveryno = d.bill_no "
			+ "left join slm_order_info soi on d.order_no = soi.contract_no||soi.contract_line_seq||soi.order_seq and nvl(soi.change_flag,'0')<>'1' "
			+ "left join slm_contract_heat_info schi on soi.contract_pk = schi.contract_pk "
			+ "where to_char(soi.deliver_date,'yyyyMMdd') < to_char(t.closetime,'yyyyMMdd') "
			+ "and slbh.solutions_name not like '%到优特%' and soi.is_over_delivery is null "
			+ "order by soi.deliver_date desc")
	public List<SlmOrderInfo> doQueryOrderForJudgeOverDelivery(@Param("time")String time);
	
	@Select("select judge_over_delivery(#{orderno}) from dual")
	public String doQueryOrderForJudgeOrder(@Param("orderno")String orderno);
	
	@Select("select distinct soi.order_no, soi.deliver_date from ydm_product_detail t "
			+ "left join slm_order_info soi on t.orderno = soi.contract_no || soi.contract_line_seq || soi.order_seq and nvl(soi.change_flag, '0') <> '1' "
			+ "left join slm_contract_heat_info schi on soi.contract_pk = schi.contract_pk "
			+ "where t.state in ('0', '2') and schi.contract_type_name <> '厂内合同' "
			+ "and t.machine_code is not null and soi.process is not null and soi.is_over_delivery is null "
			+ "and to_char(soi.deliver_date,'yyyyMMdd') < to_char(sysdate,'yyyyMMdd')")
	public List<SlmOrderInfo> doQueryKcOrderForJudgeOverDelivery();
	
	public List<SlmOrderInfo> doQueryOrderInfo(String condition, int start, int end);
	
	@Select("select t.CONTRACT_NO, t.CREATE_TIME,\n" +
			"\n" +
			"        (select sum(info.ESTIMATE_WEIGHT) from SLM_CONTRACT_LINE_INFO\n" +
			"            info\n" +
			"        where info.CONTRACT_NO = t.CONTRACT_NO\n" +
			"        and nvl(info.VALID_FLAG, '0') = '1'\n" +
			"        and info.LINE_FLAG_NO = '102608') * 0.9 as TRADE_PRICE\n" +
			"\n" +
			"        ,\n" +
			"\n" +
			"        (select sum(sd.FACTWEIGHT) from SLM_LADING_BILL_HEAT h\n" +
			"            left join SLM_LADING_BILL_DETAIL sd on h.BILL_NO = sd.BILL_NO\n" +
			"            where nvl(h.VALID_FLAG, '0') = '1'\n" +
			"              and nvl(h.MEMO, 'a') != '一次结算'\n" +
			"            and h.CONTRACT_NO = t.CONTRACT_NO) as process_price\n" +
			"\n" +
			"        from SLM_CONTRACT_HEAT_INFO t\n" +
			"        where t.CONTRACT_TYPE_NO not in ('101603')\n" +
			"        and t.CONTRACT_NO is not null\n" +
			"            and nvl(t.VALID_FLAG, '0') = '1'\n" +
			"        and t.CREATE_TIME > (to_date((to_char(sysdate, 'yyyy') - 1) || '-01',\n" +
			"            'yyyy-MM'))\n" +
			"        and t.DELIVER_DATE < sysdate\n" +
			"        order by t.CREATE_TIME  ")
	public List<SlmOrderInfo> getContractAvail ();
	
	@Select("select soi.* from SLM_ORDER_INFO soi\n" +
		      "join SLM_CUSTOMER_TRANS_SOLUTION ss on soi.SOLUTIONS_NO = ss.SOLUTIONS_NO\n" +
		      "where nvl(soi.VALID_FLAG, '0') = '1'\n" +
		      "and nvl(soi.change_flag, '0') <> '1'\n" +
		      "and soi.CONTRACT_NO in ( ${sWhere} \n" +
		      
		      "    )\n" +
		      "    and ss.SOLUTIONS_NAME != '优特到优特'\n" +
		      "    and soi.ORDER_FLAG_NO in (\n" +
		      "                '103401',\n" +
		      "                '103402',\n" +
		      "                '103403',\n" +
		      "                '103404',\n" +
		      "                '103405',\n" +
		      "                '103406',\n" +
		      "                '103407',\n" +
		      "                '103408',\n" +
		      "                '103409',\n" +
		      "                '103413',\n" +
		      "                '103414'\n" +
		      "                ) order by soi.CREATE_TIME desc ")
	public List<SlmOrderInfo> getOrdAvail (@Param("sWhere")String sWhere);
}
