<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="本地计量结果">




    <query id="ResultServer.doQuery" desc="查询">
        <![CDATA[
             SELECT RESULT_NO,
       RECORD_NO1,
       RECORD_NO2,
       RECODER1,
       RECODER2,
       RECORD_TYPE1,
       RECORD_TYPE2,
       TARE_WT,
       GROSS_WT,
       NET_WT,
       TO_CHAR(RECORD_DATE1, 'YYYY-MM-DD HH24:MI:SS')  RECORD_DATE1,
        TO_CHAR(RECORD_DATE2, 'YYYY-MM-DD HH24:MI:SS') RECORD_DATE2,
       MAT_NAME,
       MAT_TYPE,
       LOADVEHICLE_NO,
       RECEIVE_NAME,
       ORDER_NAME,
       SHIPPERS_NAME,
       TRANSPORT_NAME,
       MEMO,
       DELETE_DATE,
       DELETE_USER,
       RECODER_LOCATION1,
       RECODER_LOCATION2,
       VALIDFLAG,
       REAL_WT,
       CAR_NO,
       MAT_NUM,
       RECORD_WEIGHT1,
       RECORD_WEIGHT2
  FROM CMM_WEIGHT_RESULT
  WHERE 1=1
        ]]>
    </query>


    <query id="ResultServer.doQueryResultId" desc="查询ID">
        <![CDATA[
                 SELECT ? || TO_CHAR(SYSDATE, 'yyyyMMDD') ||
    LPAD(NVL(MAX(TO_NUMBER(SUBSTR(RESULT_NO, LENGTH(RESULT_NO) - 5))),
    0) + 1,
    6,
    '0') RESULT_NO
    FROM  CMM_WEIGHT_RESULT
    WHERE RESULT_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
        ]]>
    </query>


    <query  id="ResultServer.doSaveID" desc="保存单号">

        <![CDATA[
           INSERT INTO CMM_WEIGHT_RESULT
      (RESULT_NO,
       RECORD_NO1,
       RECORD_NO2,
       RECODER1,
       RECODER2,
       RECORD_TYPE1,
       RECORD_TYPE2,
       TARE_WT,
       GROSS_WT,
       NET_WT,
       RECORD_DATE1,
       RECORD_DATE2,
       MAT_NAME,
       MAT_TYPE,
       LOADVEHICLE_NO,
       RECEIVE_NAME,
       ORDER_NAME,
       SHIPPERS_NAME,
       TRANSPORT_NAME,
       MEMO,
       RECODER_LOCATION1,
       RECODER_LOCATION2,
       VALIDFLAG,
       REAL_WT,
       CAR_NO,
       MAT_NUM,
       RECORD_WEIGHT1,
       RECORD_WEIGHT2)
      SELECT ?,
             T1.RECORD_NO,
             T2.RECORD_NO,
             T1.RECODER,
             T2.RECODER,
             T1.RECORD_TYPE,
             T2.RECORD_TYPE,
             DECODE(T1.WT_TYPE, '0', T1.RECORD_WEIGHT, T2.RECORD_WEIGHT),
             DECODE(T1.WT_TYPE, '1', T1.RECORD_WEIGHT, T2.RECORD_WEIGHT),
             DECODE(T1.WT_TYPE, '1', T1.RECORD_WEIGHT, T2.RECORD_WEIGHT) -
             DECODE(T1.WT_TYPE, '0', T1.RECORD_WEIGHT, T2.RECORD_WEIGHT),
             T1.RECORD_DATE,
             T2.RECORD_DATE,
             DECODE(T1.WT_TYPE, '1', T1.MAT_NAME, T2.MAT_NAME),
             DECODE(T1.WT_TYPE, '1', T1.MAT_TYPE, T2.MAT_TYPE),
             DECODE(T1.WT_TYPE, '1', T1.LOADVEHICLE_NO, T2.LOADVEHICLE_NO),
             DECODE(T1.WT_TYPE, '1', T1.RECEIVE_NAME, T2.RECEIVE_NAME),
             DECODE(T1.WT_TYPE, '1', T1.ORDER_NAME, T2.ORDER_NAME),
             DECODE(T1.WT_TYPE, '1', T1.SHIPPERS_NAME, T2.SHIPPERS_NAME),
             DECODE(T1.WT_TYPE, '1', T1.TRANSPORT_NAME, T2.TRANSPORT_NAME),
             DECODE(T1.WT_TYPE, '1', T1.MEMO, T2.MEMO),
             T1.RECODER_LOCATION,
             T2.RECODER_LOCATION,
             '1',
             '',
             DECODE(T1.WT_TYPE, '1', T1.CAR_NO, T2.CAR_NO),
             DECODE(T1.WT_TYPE, '1', T1.RECORD_NUMBER, T2.RECORD_NUMBER),
             T1.RECORD_WEIGHT,
             T2.RECORD_WEIGHT
        FROM DUAL
        LEFT JOIN CMM_WEIGHT_RECORD T1
          ON T1.RECORD_NO = ?
        LEFT JOIN CMM_WEIGHT_RECORD T2
          ON T2.RECORD_NO = ?


    ]]>
    </query>

    <query  id="ResultServer.doUpdateResult" desc="更新过磅结果">
        <![CDATA[
      UPDATE CMM_WEIGHT_RESULT T
    SET (T.MAT_NAME,
         T.MAT_TYPE,
         T.LOADVEHICLE_NO,
         T.RECEIVE_NAME,
         T.ORDER_NAME,
         T.SHIPPERS_NAME,
         T.TRANSPORT_NAME,
         T.MEMO,
         T.MAT_NUM) =
        (SELECT R.MAT_NAME,
                R.MAT_TYPE,
                R.LOADVEHICLE_NO,
                R.RECEIVE_NAME,
                R.ORDER_NAME,
                R.SHIPPERS_NAME,
                R.TRANSPORT_NAME,
                R.MEMO,
                R.RECORD_NUMBER
           FROM CMM_WEIGHT_RECORD R
          WHERE R.RECORD_NO =
                DECODE(T.RECORD_TYPE1, '101', T.RECORD_NO2, T.RECORD_NO1))
  WHERE T.RESULT_NO = ?

           ]]>
    </query>


    <query  id="ResultServer.DoDeleteResult" desc="作废结果">
        <![CDATA[
    UPDATE CMM_WEIGHT_RESULT
      SET VALIDFLAG ='0',
      DELETE_USER = ?,
      DELETE_DATE = SYSDATE
      WHERE RESULT_NO = ?
           ]]>
    </query>



</queryMap>