<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="QCM_ZBS_TEMPLATE_R_MSC">
    <query id="QcmZbsTemplateRMscDAL.Query" desc="查询">
        <![CDATA[
 SELECT 
       T.PRIMARY_KEY,
       T.MSC,
       T.TBH,
       A.DESCRIPTION,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T.DELETE_NAME,
       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       DECODE(T.VALIDFLAG, '0', '无效', '1', '有效') VALIDFLAG,
       T.MEMO
 FROM QCM_ZBS_TEMPLATE_R_MSC T
 LEFT JOIN QCM_ZBS_TEMPLATE_HEAD A
 ON T.TBH = A.TBH
 WHERE
       T.MSC = '#MSC#'
       AND T.VALIDFLAG IN ('1', '#VALIDFLAG#')
       
        ]]>
    </query>
    <query id="QcmZbsTemplateRMscDAL.QueryByPk" desc="通过主键查询">
        <![CDATA[
 SELECT 
       T.MSC,
       T.TBH,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T.DELETE_NAME,
       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       T.VALIDFLAG,
       T.MEMO
 FROM QCM_ZBS_TEMPLATE_R_MSC T
 WHERE
       T.PRIMARY_KEY = '#PRIMARY_KEY#'
        ]]>
    </query>
    <query id="QcmZbsTemplateRMscDAL.Insert" desc="新增">
        <![CDATA[
 INSERT INTO QCM_ZBS_TEMPLATE_R_MSC(
        MSC,
        TBH,
        CREATE_NAME,
        CREATE_TIME,
        MEMO,
        PRIMARY_KEY)
 VALUES( 
        '#MSC#',
        '#TBH#',
        '#CREATE_NAME#',
        SYSDATE,
        '#MEMO#',
        '#PRIMARY_KEY#')
        ]]>
    </query>
    <query id="QcmZbsTemplateRMscDAL.Update" desc="修改">
        <![CDATA[
 UPDATE QCM_ZBS_TEMPLATE_R_MSC T
   SET 
        T.MSC = '#MSC#',
        T.TBH = '#TBH#',
        T.UPDATE_NAME = '#UPDATE_NAME#',
        T.UPDATE_TIME = SYSDATE,
        T.MEMO = '#MEMO#'
 WHERE
       T.PRIMARY_KEY = '#PRIMARY_KEY#'
        ]]>
    </query>
    <query id="QcmZbsTemplateRMscDAL.GetMaxPk" desc="获取最大主键">
        <![CDATA[
SELECT NVL(MAX(T.PRIMARY_KEY), 0) + 1 MAX_VALUE FROM QCM_ZBS_TEMPLATE_R_MSC T
        ]]>
    </query>
    <query id="QcmZbsTemplateRMscDAL.Delete" desc="作废">
        <![CDATA[
UPDATE QCM_ZBS_TEMPLATE_R_MSC T
   SET
       T.VALIDFLAG = '0',
       T.DELETE_NAME = '#DELETE_NAME#',
       T.DELETE_TIME = SYSDATE
WHERE
       T.PRIMARY_KEY = '#PRIMARY_KEY#'
        ]]>
    </query>
    <query id="QcmZbsTemplateRMscDAL.Resume" desc="恢复">
        <![CDATA[
UPDATE QCM_ZBS_TEMPLATE_R_MSC T
   SET
       T.VALIDFLAG = '1',
       T.DELETE_NAME = NULL,
       T.DELETE_TIME = NULL,
       T.UPDATE_NAME = '#UPDATE_NAME#',
       T.UPDATE_TIME = SYSDATE
WHERE
       T.PRIMARY_KEY = '#PRIMARY_KEY#'
        ]]>
    </query>
     <query id="QcmZbsTemplateRMscDAL.GetZbsRMscCnt" desc="查询质保书和冶金规范关联数目">
        <![CDATA[
SELECT COUNT(1)
  FROM QCM_ZBS_TEMPLATE_R_MSC T
 WHERE T.MSC = '#MSC#'
   AND T.TBH = '#TBH#'
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
</queryMap>