package market.Lms.Warehouse.mapper;

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

import market.Com.vo.PassportInfo;
import market.Lms.Warehouse.vo.IfRawMtrCoilM;
import market.Lms.Warehouse.vo.YdmProductAB;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Slm.DeliveryManagement.vo.SlmLadingBillHeat;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hnshituo.orm.GenericMapper;

@SuppressWarnings("rawtypes")
public interface YdmProductDetailMapper extends GenericMapper<YdmProductDetail, Object> {
	
	//生成卷号的方法
	public String doCreateCoilno();
	
	public List<YdmProductDetail> doQueryWebBySQL(int beginindex, int endindex,
			String starttime, String endtime, String coilno,
			String judgesteelcode, Object hmin, Object hmax, Object wmin,
			Object wmax, String storageattr, String state, String string,
			String string2, String string3, String string4, String string5,
			String string6, String memo1,String object_attr,String destpcd, int day);
	
	// doQueryWebBySQLMulti
	public List<YdmProductDetail> doQueryWebBySQLMulti(List<YdmProductDetail> coils);
	
	public List<IfRawMtrCoilM> doQueryWebBySQLNew(int beginindex, int endindex,
			String starttime, String endtime, String coilno,
			String judgesteelcode, Object hmin, Object hmax, Object wmin,
			Object wmax);
	
	public int doQueryWebBySQLNewCount(int beginindex, int endindex,
			String starttime, String endtime, String coilno,
			String judgesteelcode, Object hmin, Object hmax, Object wmin,
			Object wmax);
	

	public List<YdmProductDetail> doQueryWebBySQLApp(String coilno,String storageattr,String state);

	public List<YdmProductDetail> doQueryWebBySQLs(int beginindex,
			int endindex, String starttime, String endtime, YdmProductDetail ypd,
			 Object hmin, Object hmax, Object wmin,Object wmax);
	public int doQueryWebBySQLCounts(String starttime, String endtime, YdmProductDetail ypd,
			Object hmin, Object hmax, Object wmin, Object wmax);

	public int doQueryWebBySQLCount(String starttime, String endtime,
			String coilno, String judgesteelcode, Object hmin, Object hmax,
			Object wmin, Object wmax, String storageattr, String state,
			String string, String string2, String string3, String string4,
			String string5, String string6,String memo1,String objectAttr, int day);

	
	

	public void doUpdate(YdmProductDetail ypd);

	public void doUpdateKehu(String ypd);

	public void doUpdateKehuCanl(String ypd);

	public void doUpdateApi(YdmProductDetail ypd);

	public void doInsert(YdmProductDetail ypd);

	public void doDelete(String coilno, String boxno);

	public YdmProductDetail doFind(String coilno, String boxno);

	public List<YdmProductDetail> doFindcount(String coilno, String boxno);

	public List<HashMap> doQueryWebBySQLOther(int beginindex, int endindex,
			String starttime, String endtime, String coilno,
			String judgesteelcode, Object thick, Object width, Object wjmin,
			Object wjmax, String Storageattr, String string);

	public int doQueryWebBySQLCountOther(String starttime, String endtime,
			String coilno, String judgesteelcode, Object thick, Object width,
			Object wjmin, Object wjmax, String Storageattr, String string);

	// 成品分条充当
	public void doFinshedProductActUpdate(YdmProductDetail ydmProductDetail);

	// //分条脱单
	public void doMaterialReplaceUpdate(YdmProductDetail ydmProductDetail);

	public void doMaterialReplaceUpdateB(YdmProductDetail ydmProductDetail);

	public List<YdmProductDetail> doQueryEnable(int beginindex, int endindex,
			String ALLOT_NO, String storageattr, String state);

	public int doQueryEnableCount(String allot_no, String storageattr,
			String state);

	public List<YdmProductDetail> doQueryWebBySQLDelivery(int beginindex,
			int endindex, List<String> listorderno, String storageattr,
			String state);

	public int doQueryWebBySQLDeliveryCount(List<String> listorderno,
			String storageattr, String state);

	public List<YdmProductDetail> doQueryWebBySQLDeliveryB(int beginindex,
			int endindex, List<String> listorderno, String storageattr,
			String state, String bill);

	public int doQueryWebBySQLDeliveryCountB(List<String> listorderno,
			String storageattr, String state, String bill);

	public List<YdmProductDetail> doQueryWebBySQLOutBill(int beginindex,
			int endindex, String starttime, String endtime, String coilno,
			String judgesteelcode, Object thick, Object width, Object wjmin,
			Object wjmax, String string, String string2);

	public int doQueryWebBySQLOutBillCount(String starttime, String endtime,
			String coilno, String judgesteelcode, Object thick, Object width,
			Object wjmin, Object wjmax, String string, String string2);

	public List<YdmProductDetail> doQueryWebBySQLOnBill(int beginindex,
			int endindex, String starttime, String endtime, String coilno,
			String steel_name, Object thick, Object width, Object wjmin,
			Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature, String materailcoilno, String string, String ord_pk);

	public int doQueryWebBySQLOnBillCount(String starttime, String endtime,
			String coilno, String steel_name, Object thick, Object width,
			Object wjmin, Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature, String materailcoilno, String string, String ord_pk);

	public void doUpdateRevoke(String queryNo, String addNo, double act_wgt,
			double wgt, double len);

	public List<YdmProductDetail> doQueryWebBySales(int i, int j,
			String startTime, String endTime, String coilno,
			String judgesteelcode, Object thick, Object width, Object wjmin,
			Object wjmax, String storageattr, String orderno,String order_nature, String string, String whole);

	public List<YdmProductDetail> doQueryWebBySale(int i, int j,
			String startTime, String endTime, String coilno,
			String judgesteelcode, Object thick, Object width, Object wjmin,
			Object wjmax, String storageattr, String orderno);

	public int doQueryWebBySalesCount(String startTime, String endTime,
			String coilno, String judgesteelcode, Object thick, Object width,
			Object wjmin, Object wjmax, String storageattr, String orderno,String order_nature,String string, String whole);

	public int doQueryWebBySaleCount(String startTime, String endTime,
			String coilno, String judgesteelcode, Object thick, Object width,
			Object wjmin, Object wjmax, String storageattr, String orderno);

	public List<YdmProductDetail> doQueryDetByLad(String bill_no);

	public String doQueryCarByLad(String bill_no);

	public String doQueryOrder(String orderno);

	@Select("select * from YDM_PRODUCT_DETAIL t where (COILNO =#{wL}  or BOXNO = #{wL} or MATERAILCOILNO= #{wL}) and STATE in ('0','2')")
	public List<YdmProductDetail> doQueryYxx(@Param("wL") String wL,
			@Param("storageattr") String storageattr,
			@Param("State") String State);
			
			
			
	@Select("select (select b.base_name from com_base_info b where b.base_code = t.storageattr) storageattr,decode(t.state,'-1','待入库', '0','在库', '1', '移送在途',  '2', '发运锁定', '4', '包装出库', '5','出库', t.state) state,t.coilno,t.materailcoilno  from YDM_PRODUCT_DETAIL t where (COILNO =#{wL}  or BOXNO = #{wL} or MATERAILCOILNO= #{wL}) ")
	public List<YdmProductDetail> doQueryYxxA(@Param("wL") String wL);
	

	// 可充当卷号查询
	public List<HashMap> doFindPD();

	public YdmProductDetail doFindById(YdmProductDetail yd);

	public void DoUpdateRM(YdmProductDetail yd);

	List<YdmProductDetail> doQueryWebByProcess(YdmProductDetail ypd, String string, String string2);

	

	List<YdmProductDetail> doQueryWebByProcess1(String s1, String s2, String startTime,
			String endTime, String coilno, String judgesteelcode, Object hmin,
			Object hmax, Object wmin, Object wmax, String storageattr,
			String state, String materailcoilno, String orderno,
			String prodorderno, String buttressno, String areano,
			String customer_no, String memo5);

	public List<YdmProductAB> _doQueryABWeb(String memo1,String storageattr);
	
	public List<YdmProductAB> doQueryABWeb(String memo1);
	 
    /***
     * @param memo1
     * @param sto (成品库/贸易库/原料库  编号)
     * @return
     */
	public List<HashMap> doQueryABWeb1(String memo1,String memo2,YdmProductDetail ydm);


	public double doFindTda(String indate);
	
	public double doFindMda(String indate);

	public double doFindZpda(String indate);
	
	public double doFindPda(String indate);
	
	public double doFindPdf(String indate);
	public List<YdmProductDetail> _doFindPdf(String indate);
	
	public double doFindPdd(String indate);
	public List<YdmProductDetail> _doFindPdd(String indate);

	public List<HashMap> doFindResultByCoilno(YdmProductDetail ypd);
	
	public void doTuoDan(String deliveryno);
	public void doGuaDan(String deliveryno);
	
	public YdmProductDetail check(YdmProductDetail ydm);
	
	public List<YdmProductDetail> _doQueryWebBySQL(String intime,String storageattr);
	
	public List<YdmProductDetail> newInDate(String newtime,String storageattr);
	public List<YdmProductDetail> newOutDate(String newtime,String storageattr);
	
	public List<YdmProductDetail> findYdmQS(@Param("param1")YdmProductDetail ydm,@Param("index")int index,@Param("size")int size);
	public int findYdmQSCount(@Param("param1")YdmProductDetail ydm);
	public List<YdmProductDetail> doCheckQS(YdmProductDetail ydm);
	
	//更新综合判定结果
     void updateUlJudgeResult(String ulid,String result);
    
    public List<SlmLadingBillHeat> findBillHeats(@Param("heat")SlmLadingBillHeat ydm,@Param("index")int index,@Param("size")int size,@Param("startTime")String startTime,@Param("endTime")String endTime);
    public int CountfindBillHeat(@Param("heat")SlmLadingBillHeat ydm,@Param("startTime")String startTime,@Param("endTime")String endTime);
	
    /**
	 * 查询没有销售订单号并且在库的所有成品
	 * @return
	 */ 
    public List<YdmProductDetail> selectYdm();

	/**
	 * 开平库存品查询
	 * @param materailcoilno 
	 * @param string 
	 * @param condition 
	 * @return
	 */
	public List<YdmProductDetail> doQueryCuttoLengthWeb(int beginindex,
			int endindex, String starttime, String endtime, String coilno,
			String steel_name, Object thick, Object width, Object wjmin,
			Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature, String materailcoilno, String string, String condition);

	/**
	 * 开平库存品查询
	 * @param string 
	 * @param condition 
	 * @return
	 */
	public int doQueryCuttoLengthWebCount(String starttime, String endtime,
			String coilno, String steel_name, Object thick, Object width,
			Object wjmin, Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature,String materailcoilno, String string, String condition);

	/**
	 * 罩退库存品查询
	 * @param materailcoilno 
	 * @param string 
	 * @param condition 
	 * @return
	 */
	public List<YdmProductDetail> doQueryAnnealWeb(int beginindex,
			int endindex, String starttime, String endtime, String coilno,
			String steel_name, Object thick, Object width, Object wjmin,
			Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature, String materailcoilno, String string, String condition);
	/**
	 * 罩退库存品查询
	 * @param string 
	 * @param condition 
	 * @return
	 */
	public int doQueryAnnealWebCount(String starttime, String endtime,
			String coilno, String steel_name, Object thick, Object width,
			Object wjmin, Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature,String materailcoilno, String string, String condition);
	
	/**
	 * 轧制库存品查询
	 * @param materailcoilno 
	 * @param string 
	 * @param condition 
	 * @return
	 */
	public List<YdmProductDetail> doQueryRollingWeb(int beginindex,
			int endindex, String starttime, String endtime, String coilno,
			String steel_name, Object thick, Object width, Object wjmin,
			Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature, String materailcoilno, String string, String condition);
	/**
	 * 轧制库存品查询
	 * @param string 
	 * @param condition 
	 * @return
	 */
	public int doQueryRollingWebCount(String starttime, String endtime,
			String coilno, String steel_name, Object thick, Object width,
			Object wjmin, Object wjmax, String judgesteelcode, Object thickmin,
			Object thickmax, String order_no,String order_nature,String storage_attr,String ordernature,String materailcoilno, String string, String condition);

	//根据物料号更新上表结果
	public void upresultU(String result_code,String object_no,String sid);
	//根据物料号更新下表结果
    public void upresultD(String result_code,String object_no,String sid);
    //根据物料号更新边部结果
    public void upresultE(String result_code,String object_no,String sid);
    //根据物料号更新边部结果
    public void upresultB(String result_code,String object_no);
    
    // 通过销售订单号更新判定结果
    public void doUpdateByOrderno(String orderno,String result1,String result2,String inspection_lot);
    
    // 2018年12月1日 质量模块 ：查询所有的投料卷
    public List<YdmProductDetail> doQuaryDetailForM(String condition,int beginindex, int endindex);
    
    // 2018年12月1日 质量模块 ：查询所有的投料卷
    public List<HashMap> doQuaryDetailForC(String condition);
    
	//2019年2月20日提货单管理提货单明细 ，点击原料卷号，弹出显示物料信息
    public List<YdmProductDetail> doQuaryByMaterialCoilno(String condition);
    
    //根据卷号更新库存表材质判定结果和材质判定结果id(PHYSRESULT)
    public void updatePhysResultByCoilno(String coilno,String result,String resultId);
    
    //根据卷号更新库存表 的 探伤判定结果和探伤判定结果id(SPYRESULT)
    public void updateSpyResultByCoilno(String coilno,String result,String resultId);
    
    //根据卷号更新库存表 的 卡量判定结果和卡量判定结果id(MEASURE_RESULT)
    public void updateMeaResultByCoilno(String coilno,String result,String resultId);

    // 生产订单进程
	public List<YdmProductDetail>  doQueryOrderMat(@Param("prodorderno") String prodorderno);
	
	//20190508 4mm和12mm(纵剪) 查询投料卷下的物料的质量信息
	public List<HashMap> doQuaryDetailZJ(String condition);
	
	//20190508 3mm(横剪) 查询投料卷下的物料的质量信息
	public List<HashMap> doQuaryDetailHJ(String condition);
	
	//20190508 (退火) 查询投料卷下的物料的质量信息
	public List<HashMap> doQuaryDetailTH(String condition);
		
	//20190508 (平整) 查询投料卷下的物料的质量信息
	public List<HashMap> doQuaryDetailPZ(String condition);
	
	//20190531 (轧机) 查询投料卷下的物料的质量信息
	public List<HashMap> doQuaryDetailZhaJ(String condition);
	
	//20190615 (酸洗) 查询投料卷下的物料的质量信息
	public List<HashMap> doQuaryDetailSX(String condition);
	
	//20190712 根据卷号清除库存表的质量信息
	public void removeDetailQmsInfo(String coilno);
		
	public List<YdmProductDetail> doQuaryQmsDetailInfo(YdmProductDetail ypd);
	
	public List<HashMap> doQueryYpdHistory(String condition);
	
	public List<HashMap> doQueryYpdHistoryBefore(String condition);
	
	public List<HashMap> doQueryKCHistory(String startTime, String endTime);

	public List<HashMap> doQueryKFLHistory(String startTime, String endTime);

	public List<HashMap> doQueryFYSDHistory(String startTime, String endTime);

	public List<HashMap> doQueryRCKLHistory(String startTime, String endTime);
	
	List<HashMap> doQueryYpdGuaDan(int beginindex, int endindex, YdmProductDetail ypd, String condition, String thickmax,String thickmin);
	public int doQueryYpdGuaDanCount(int beginindex, int endindex, YdmProductDetail ypd, String condition, String thickmax, String thickmin);
	
	public List<PassportInfo> doQuaryLmsPassPortInfoSpecWeight(@Param("param")List<String> coilList);
	
	public List<YdmProductDetail> doReportWebBySQL(String condition, YdmProductDetail ypd, int begin, int end);
	
	public int doReportWebBySQLCount(String condition, YdmProductDetail ypd);
	
	public String querySteelNmByJudgeCode(String coilno);
	
	List<HashMap> doQueryCButtress(@Param("param")List<String> coilList);
	
	String doQueryCButtressOne(@Param("coilno")String coil);
	
	@Select("select t.COILNO, t.STORAGEATTR, si.CUSTOMER_NAME, cbs.STEEL_NAME, t.THICK\n" +
		      "          as THICK,                                                             t\n" +
		      "    .WIDTH as WIDTH, (t\n" +
		      "    .FACTWEIGHT / 1000) as FACTWEIGHT, t.ORDERNO, si\n" +
		      "    .BALANCE_PRICE, (si.TRADE_PRICE * (t.FACTWEIGHT / 1000)) as YF,\n" +
		      "       ((si.BALANCE_PRICE + si.TRADE_PRICE) * (t.FACTWEIGHT) / 1000) as HTZE,\n" +
		      "    (to_char(to_date(to_char(sysdate, 'yyyyMMdd'),\n" +
		      "    'yyyyMMdd') - to_date(substr(y.OPR_TIME, 1, 8), 'yyyyMMdd'))) as KFTS,\n" +
		      "       yb.buttressname as areaname,ybb.buttressname as buttressname, ypb\n" +
		      "           .locality as locality\n" +
		      "from YDM_PRODUCT_DETAIL t\n" +
		      "    left join SLM_ORDER_INFO si on t.ORDERNO =\n" +
		      "    si.CONTRACT_NO || si.CONTRACT_LINE_SEQ || si.ORDER_SEQ and nvl(si.CHANGE_FLAG,\n" +
		      "        '0') != '1'\n" +
		      "left join PLN_MATERIEL_DETAIL pmd on t.COILNO = pmd.OBJECT_NO\n" +
		      "left join COM_BASE_STEEL cbs on cbs.STEEL_CODE = t.STEELCODE\n" +
		      "left join ydm_product_buttresslist ypb on t.coilno = ypb.coilno\n" +
		      "left join ydm_base_buttressconfig ybb on ypb.buttressno = ybb.buttressno\n" +
		      "left join ydm_base_buttressconfig yb on yb.buttressno = ybb.sortcode\n" +
		      "left join (\n" +
		      "    select row_number() over (partition by mo.COILNO order by mo.OPR_TIME\n" +
		      "        desc) rn, mo.*\n" +
		      "    from MES_OPR_LOG mo\n" +
		      "    where OPR_FUNCTION = '自动判定是否可发运'\n" +
		      "    ) y on y.COILNO = t.COILNO and y.rn = 1\n" +
		      "\n" +
		      "where nvl(t.IS_CAN_LOAD, '0') = '1'\n" +
		      "and t.STATE = '0'\n" +
		      "and t.JUDGERESULT is not  null\n" +
		      "and t.object_attr = '507101'\n" +
		      "\n" +
		      "and t.ORDERNO is not null\n" +
		      "    and (\n" +
		      "        (si.ORDER_NATURE is not null and si.ORDER_NATURE = '1'\n" +
		      "            and t.storageattr in ('500201','500205','500203')\n" +
		      "\t\t\tand t.object_attr='507101')\n" +
		      "        or (si.ORDER_NATURE is not null and si.ORDER_NATURE = '2'\n" +
		      "            and si.WHOLE_COIL != '1' and pmd.next_process_code is null\n" +
		      "            and t.storageattr in ('500203','500205','500201'))\n" +
		      "        or (si.ORDER_NATURE is not null and si.ORDER_NATURE = '2'\n" +
		      "            and si.WHOLE_COIL = '1' and pmd.next_process_code is null\n" +
		      "            and t.storageattr in ('500201','500205','500203','500210'))\n" +
		      "        or (si.ORDER_NATURE is not null and si.ORDER_NATURE = '3'\n" +
		      "            and t.storageattr in ('500203','500210','500201','500205'))\n" +
		      "        or (si.ORDER_NATURE is not null and si.ORDER_NATURE = '4'\n" +
		      "            and t.storageattr in ('500203','500210','500205'))\n" +
		      "        or (si.ORDER_NATURE is not null and si.ORDER_NATURE = '5'\n" +
		      "            and (t.storageattr in ('500203','500205')\n" +
		      "\t\t\t      or (t.storageattr in ('500201') and t.coilno like '%S%')\n" +
		      "\t\t\t    ))\n" +
		      "        or (si.ORDER_NATURE is not null and si.ORDER_NATURE = '2'\n" +
		      "            and WEIGHT_TYPE_NO = '102301' and t.coilno not like '%B'\n" +
		      "            and pmd.next_process_code is null)\n" +
		      "    )\n" +
		      "order by t.CUSTOMER_NM, t.ORDERNO, t.COILNO")
	List<HashMap> doQueryKF();
	
	@Select("select count(1) from YDM_PRODUCT_DETAIL_HISTORY where STATDATE = #{statDate} and BUTTRESSNO is null")
	int findIsAllNew (@Param("statDate") String statDate);
	
	void insertToQSys(@Param("coilno")String coilno, @Param("isfinal")String isfinal, @Param("lot")String lot);
	

	void insertToQSysTh(@Param("coilno")String coilno, @Param("isfinal")String isfinal, @Param("lot")String lot);
	
	void insertToQSysTBLogTh(String coilno);
	
	void insertToQSysTB(String coilno);
	
	void insertToQSysTBLog(String coilno);
	
	
	int countToQSys(String coilno);
	
	int countToSysLog(String coilno);
	
	@Select("select count(1) from qcm_ord_design_std_pic@LINK_sq t where t.design_key = #{orderno} and t.PROCESS_CODE='YT1'")
	int isFSJy(@Param("orderno") String orderno);
	
	List<HashMap> doQueryYpdGuaDanAuto(String orderno);
	
	@Select("select t.COILNO,t.WIDTH,t.LENGTH,t.PROD_NAME,t.THICK,t.ORDERNO,cbs.STEEL_NAME\n" +
      "    as STEELCODE,t.FACTWEIGHT / 1000 as FACTWEIGHT,t.MATERAILCOILNO,t\n" +
      "        .STORAGEATTR,t.JUDGERESULT, t.OBJECT_ATTR\n" +
      "from YDM_PRODUCT_DETAIL t\n" +
      "    left join COM_BASE_STEEL cbs on cbs.STEEL_CODE = t.JUDGESTEELCODE\n" +
      "where t.STATE in ('0', '7')")
	List<YdmProductDetail> ypdHisQ ();
	
	
	@Select("select COILNO from YDM_PRODUCT_DETAIL where STATE in ('0', '2', '7') and STORAGEATTR is not null ")
	List<YdmProductDetail> ypdCurQ();
	
	@Insert("INSERT INTO YDM_DETAIL_SYNC (COILNO, OPERATION,GUID) VALUES (#{coilno}, '1', sys_guid())")
	void insertKC(@Param("coilno")String coilno);
	
	@Update("UPDATE TBH02_COIL_COMM@LINK_sq H\n" +
      "   SET H.COIL_STAT          = 2,\n" +
      "       H.BEF_PROG_CD        = H.CUR_PROG_CD,\n" +
      "       H.BEF_PROG_CD_DTIME  = H.CUR_PROG_CD_DTIME,\n" +
      "       H.BEF_PROG_CD_PGM    = H.CUR_PROG_CD_PGM,\n" +
      "       H.CUR_PROG_CD        = 'SRC',\n" +
      "       H.CUR_PROG_CD_DTIME  = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MIDD'),\n" +
      "       H.CUR_PROG_CD_PGM    = 'YTGRETURN',\n" +
      "       H.ORD_NO             = '',\n" +
      "       H.ORD_SEQ            = '',\n" +
      "       H.ORD_FL             = '2',\n" +
      "       H.INSTR_COIL_THK     = '',\n" +
      "       H.INSTR_COIL_WTH     = '',\n" +
      "       H.CUR_LOAD_LOC_DTIME = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MIDD')\n" +
      " WHERE H.OLD_SAMPL_NO = #{coilno}" +
      "   AND H.CUR_PROG_CD='SGF'")
	void updateJbReturn(@Param("coilno")String coilno);
	
	@Insert("insert into tbh02_coil_trans@LINK_sq t\n" +
      "   (t.TRANS_NO,\n" +
      "    t.COIL_NO,--退回卷号\n" +
      "    t.TRANS_FLAG,\n" +
      "    t.REG_ID,--操作人\n" +
      "    t.REG_USER_TIME)\n" +
      " values\n" +
      "   ((select nvl(max(t1.TRANS_NO), 0) + 1 from tbh02_coil_trans@LINK_sq t1),\n" +
      "    #{coilno},\n" +
      "    '9',\n" +
      "    #{name},\n" +
      "    to_char(sysdate, 'YYYYMMDDHH24MISS'))")
	void insertReturnLog(@Param("coilno")String coilno, @Param("name")String name);
	
	// 往库存同步里写:
	@Insert("INSERT INTO YDM_DETAIL_SYNC (COILNO, OPERATION,GUID) VALUES (#{coilno}, '2', sys_guid())")
	void kctbYdd(@Param("coilno")String coilno);
	
	@Select("select CRAFT_PARAM_DESC from SLM_ORD_DESIGN_MSC_PL_STI where DESIGN_KEY = #{orderno} and PROCESS_CODE = 'A' order by BACKLOG_SEQ")
	List<String> lzThick(@Param("orderno")String orderno);
	
	@Select("select count(1) from MES_RCM_D where COIL_NO like concat(concat('%', #{coilno}), '%')")
	int isLz(@Param("coilno")String coilno);
	
	@Select("select count(1) from YDM_PRODUCT_DETAIL where MATERAILCOILNO = #{mat_coil} and COILTYPE = '0' and SOURCE = '1' and MACHINE_CODE is null and OBJECT_ATTR = '507102' and STORAGEATTR = '500201'")
	int isWaiGouCoil(@Param("mat_coil")String mat_coil);
	
	@Select("select count(1) from SLM_LADING_BILL_DETAIL t left join SLM_LADING_BILL_HEAT sh on t.BILL_NO = sh.BILL_NO where nvl(sh.MEMO, 'a') = '一次结算' and t.COILNO = #{mat_coil}")
	int isHasYcJs(@Param("mat_coil")String mat_coil);
	
	// isPdCoil
	@Select("select count(1) from qcm_judge_ultimate@link_sq t\n" +
		      "join QCM_JUDGE_YT_COIL_RESULT@link_sq res on t.material_no = res.coil_no\n" +
		      "where t.material_no = #{coilno}")
	int isPdCoil(@Param("coilno")String coilno);
	
	// changeResult
	@Update("update QCM_JUDGE_YT_COIL_RESULT@link_sq\n" +
		      "set JUDGERESULT = '0',\n" +
		      "JUDGERESULT_DESC = null,\n" +
		      "JUDGEID = null,\n" +
		      "R_CHEMRESULT = '0',\n" +
		      "R_CHEMRESULT_DESC = null,\n" +
		      "R_CHEMID = null, R_CIC_IS_LOCK = '0' \n" +
		      "where coil_no = #{coilno}")
	void changeResult(@Param("coilno")String coilno);
	
	// changeUltimate
	@Update(" update qcm_judge_ultimate@link_sq a\n" +
      " set a.cancel_memo ='优特钢重新判定',a.cancel_name =#{name},a.cancel_time = sysdate\n" +
      "  where a.utm_id = #{id}")
	void changeUltimate(@Param("name")String name, @Param("id")String id);
	
	// changeLog
	@Insert("insert into qcm_judge_log@link_sq\n" +
      "\t\t(judge_type, material_no, prod_line)\n" +
      "\t\tvalues\n" +
      "\t\t('R', #{coilno}, 'YT1')")
	void changeLog(@Param("coilno")String coilno);
	
	List<HashMap> doQueryYjTd(String condition, YdmProductDetail ypd, int begin, int end);
	
	@Select("select y.ORDER_NO from YDM_PRODUCT_DETAIL t\n" +
      "left join (\n" +
      "    select row_number() over (partition by OBJECT_NO order by CREATE_TIME desc)rn\n" +
      "    ,OBJECT_NO,ORDER_NO\n" +
      "    from PLN_MAT_REPLACE_LOG where OPT_TYPE = '0'\n" +
      ")y on t.COILNO = y.OBJECT_NO where y.rn = '1' and t.COILNO = #{coilno}")
	String getLastOrd(@Param("coilno")String coilno);
	
	// 往库存同步里写:
	@Insert("insert into READY_SEND_ZCSJ (BILL_NO, DATA) values (#{bill_no}, #{data})")
	void readySendZCSJ(@Param("bill_no")String bill_no, @Param("data")String data);
	
	// 获取所有未发送综判异动点的卷：
	@Select("select * from YDM_PRODUCT_DETAIL t where t.STORAGEATTR = '500203' and nvl(t.IS_CAN_LOAD, '0') = '0' and t.STATE in ('0', '2', '7') and t.CREATEDATE <= to_date('2024-04-25 12:24:00', 'yyyy-MM-dd HH24:mi:ss') order by t.CREATEDATE desc")
	public List<YdmProductDetail> queryUnSendUltYdd();
	
	@Delete("delete from IF_RAW_MTR_COIL_M where COIL_NO = #{coilno}")
	void delif (@Param("coilno")String coilno);
	
	@Delete("delete from XMLZ.IF_RAW_MTR_COIL_M where COIL_NO = #{coilno}")
	void deliflz (@Param("coilno")String coilno);
	
	@Select("select t2.OBJECT_NO from pln_lengthwise_plan t1\n" +
      "left join pln_lengthwise_plan_detail t2 on t1.lw_plan_no = t2.lw_plan_no\n" +
      "left join mes_cr_slitting_m t3 on t2.lw_plan_no = t3.schedule_no and t2.object_no_vt = t3.material_no_vt\n" +
      "where t1.machine_code in ('M0001','M0002')\n" +
      "and t1.status >= '0PLW03'\n" +
      "and t3.HAND_OVER_STATUS = '0'\n" +
      "and t1.plan_seq >= (select min(plan_seq) from\n" +
      "pln_lengthwise_plan x where x.machine_code in ('M0001','M0002'))\n" +
      "union\n" +
      "select t2.OBJECT_NO from pln_skinrolling_plan t1\n" +
      "left join pln_skinrolling_plan_detail t2 on t1.sr_plan_no = t2.sr_plan_no\n" +
      "left join mes_tpm_m t3 on t2.sr_plan_no = t3.schedule_no\n" +
      "where t1.machine_code = 'M0007'\n" +
      "    and t1.status >= '0PSR03'\n" +
      "    and t3.HAND_OVER_STATUS = '0'\n" +
      "    and t1.plan_seq >= (select min (plan_seq)\n" +
      "                    from pln_skinrolling_plan x\n" +
      "                where x.machine_code = 'M0007'\n" +
      "                    and x.status in ('0PSR02','0PSR03')\n" +
      "                )\n" +
      "union\n" +
      "select t2.OBJECT_NO from pln_rolling_plan t1\n" +
      "join pln_rolling_plan_detail t2 on t1.rl_plan_no = t2.rl_plan_no\n" +
      "left join mes_rcm_m t3 on t2.rl_plan_no = t3.schedule_no and t2.object_no_vt = t3.material_no_vt\n" +
      "where t1.machine_code = 'M0008'\n" +
      "    and t1.status >= '0PRL03'\n" +
      "        and nvl(t3.HAND_OVER_STATUS, '0') = '0'\n" +
      "    and t1.plan_seq >= (select min(plan_seq)\n" +
      "        from pln_rolling_plan x\n" +
      "    where x.machine_code= 'M0008'\n" +
      "        and (x.status = '0PRL02' or x.status = '0PRL03'))\n" +
      "union\n" +
      "select t2.OBJECT_NO from pln_anneal_plan t1\n" +
      "left join pln_anneal_plan_detail t2 on t1.an_plan_no = t2.an_plan_no\n" +
      "left join mes_cr_anneal_m t3 on t2.an_plan_no = t3.schedule_no and t2.object_no_vt = t3.material_no_vt\n" +
      "where t1.machine_code in ('M0004','M0005','M0006')\n" +
      "\t\t   and t1.status >= '0PAN02' and t3.HAND_OVER_STATUS = '0'\n" +
      "\t\t   and t1.plan_seq >= (select min(plan_seq)\n" +
      "                         from pln_anneal_plan x\n" +
      "                        where x.machine_code in ('M0004','M0005','M0006')\n" +
      " \t\tand (x.status = '0PAN02' or x.status = '0PAN03'))\n" +
      "\t\t   and nvl(t3.hand_over_time,sysdate)>sysdate-1")
	List<String> getProdIng();
}
