<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="CRAFT_AUTO_PEOPLE （生成工具：代码生成工具4.0   访问地址：http://172.16.2.128/tool/）">
    <query id="CraftAutoPeopleDAL.Query" desc="查询">
        <![CDATA[
SELECT T.PK,
       T.UNIT_CODE,
       A.DEPARTNAME UNIT_DESC,
       T.AUDIT_CODE,
       B.USERNAME AUDIT_DESC,
       T.AUDIT_CODE1,
       C.USERNAME AUDIT_DESC1,
       T.APPROVE_CODE,
       D.USERNAME APPROVE_DESC,
       T.APPROVE_CODE1,
       E.USERNAME APPROVE_DESC1,
       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,
       DECODE(T.AUTO_FLAG, '0', 'False', '1', 'True') AUTO_FLAG
  FROM CRAFT_AUTO_PEOPLE T
  LEFT JOIN CORE_APP_DEPARTMENT A
    ON A.DEPARTID = T.UNIT_CODE
  LEFT JOIN CORE_APP_USER B
    ON B.USERID = T.AUDIT_CODE
  LEFT JOIN CORE_APP_USER C
    ON C.USERID = T.AUDIT_CODE1
  LEFT JOIN CORE_APP_USER D
    ON D.USERID = T.APPROVE_CODE
  LEFT JOIN CORE_APP_USER E
    ON E.USERID = T.APPROVE_CODE1
 WHERE T.AUTO_FLAG = DECODE({0}, 'Auto', '1', '0')
 ORDER BY T.AUTO_FLAG DESC,
          T.UNIT_CODE,
          T.AUDIT_CODE,
          T.AUDIT_CODE1,
          T.APPROVE_CODE,
          T.APPROVE_CODE1
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.QueryPopup" desc="查询">
        <![CDATA[
SELECT T.PK,
       T.UNIT_CODE,
       A.DEPARTNAME UNIT_DESC,
       T.AUDIT_CODE,
       B.USERNAME AUDIT_DESC,
       T.AUDIT_CODE1,
       C.USERNAME AUDIT_DESC1,
       T.APPROVE_CODE,
       D.USERNAME APPROVE_DESC,
       T.APPROVE_CODE1,
       E.USERNAME APPROVE_DESC1,
       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,
       DECODE(T.AUTO_FLAG, '0', 'False', '1', 'True') AUTO_FLAG
  FROM CRAFT_AUTO_PEOPLE T
  LEFT JOIN CORE_APP_DEPARTMENT A
    ON A.DEPARTID = T.UNIT_CODE
  LEFT JOIN CORE_APP_USER B
    ON B.USERID = T.AUDIT_CODE
  LEFT JOIN CORE_APP_USER C
    ON C.USERID = T.AUDIT_CODE1
  LEFT JOIN CORE_APP_USER D
    ON D.USERID = T.APPROVE_CODE
  LEFT JOIN CORE_APP_USER E
    ON E.USERID = T.APPROVE_CODE1, SLM_ORDER_LINE F
 WHERE T.AUTO_FLAG = '0'
   AND F.ORD_LN_PK = {0}
   AND EXISTS (SELECT 1
          FROM COM_MSC G
         WHERE G.MSC = F.MSC
           AND G.UNIT_CODE_PROCESS = T.UNIT_CODE)
 ORDER BY T.AUTO_FLAG DESC,
          T.UNIT_CODE,
          T.AUDIT_CODE,
          T.AUDIT_CODE1,
          T.APPROVE_CODE,
          T.APPROVE_CODE1
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.QueryByPk" desc="通过主键查询">
        <![CDATA[
 SELECT 
       T.PK,
       T.UNIT_CODE,
       T.AUDIT_CODE,
       T.AUDIT_CODE1,
       T.APPROVE_CODE,
       T.APPROVE_CODE1,
       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
 FROM CRAFT_AUTO_PEOPLE T
 WHERE
       T.PK = '#PK#'
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.Insert" desc="新增">
        <![CDATA[
 INSERT INTO CRAFT_AUTO_PEOPLE(
        PK,
        UNIT_CODE,
        AUDIT_CODE,
        AUDIT_CODE1,
        APPROVE_CODE,
        APPROVE_CODE1,
        CREATE_NAME,
        CREATE_TIME,
        AUTO_FLAG)
 VALUES( 
        '#PK#',
        '#UNIT_CODE#',
        '#AUDIT_CODE#',
        '#AUDIT_CODE1#',
        '#APPROVE_CODE#',
        '#APPROVE_CODE1#',
        '#CREATE_NAME#',
        SYSDATE,
        '#AUTO_FLAG#')
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.Update" desc="修改">
        <![CDATA[
 UPDATE CRAFT_AUTO_PEOPLE T
   SET 
        T.PK = '#PK#',
        T.UNIT_CODE = '#UNIT_CODE#',
        T.AUDIT_CODE = '#AUDIT_CODE#',
        T.AUDIT_CODE1 = '#AUDIT_CODE1#',
        T.APPROVE_CODE = '#APPROVE_CODE#',
        T.APPROVE_CODE1 = '#APPROVE_CODE1#',
        T.UPDATE_NAME = '#UPDATE_NAME#',
        T.UPDATE_TIME = SYSDATE,
        T.AUTO_FLAG = '#AUTO_FLAG#'
 WHERE
       T.PK = '#PK#'
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.GetMaxPk" desc="获取最大主键">
        <![CDATA[
SELECT NVL(MAX(PK), 0) + 1 MAX_VALUE FROM CRAFT_AUTO_PEOPLE T
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.Delete" desc="删除">
        <![CDATA[
DELETE FROM (SELECT * FROM CRAFT_AUTO_PEOPLE T WHERE T.PK = '#PK#')
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.GetUnit" desc="获取管理科室">
        <![CDATA[
SELECT  A.DEPARTNAME DEPARTNAME1, T.DEPARTID, T.DEPARTNAME
  FROM CORE_APP_DEPARTMENT T, CORE_APP_DEPARTMENT A
 WHERE T.PID IN ('002001007', '002001001','002023005')
 AND A.DEPARTID = T.PID
 ORDER BY A.DEPARTNAME, T.DEPARTNAME
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.GetAudit" desc="获取审核人">
        <![CDATA[
SELECT B.DEPARTNAME DEPARTNAME1, T.DEPARTID, T.DEPARTNAME, A.USERID, A.USERNAME
  FROM CORE_APP_DEPARTMENT T, CORE_APP_USER A, CORE_APP_DEPARTMENT B
 WHERE (T.PID IN ('002001007', '002001001','002023005') OR ( T.DEPARTID = '002023019'))
   AND A.DEPTID = T.DEPARTID
   AND B.DEPARTID = T.PID
   ORDER BY B.DEPARTNAME, T.DEPARTNAME, A.USERNAME
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.IsExistUnit" desc="科室是否重复">
        <![CDATA[
SELECT COUNT(1)
  FROM CRAFT_AUTO_PEOPLE T
 WHERE T.UNIT_CODE = {0}
   AND T.AUTO_FLAG = '1'
   AND T.PK <> {1}
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.IsExistUnit2" desc="科室是否重复(人工审核)">
        <![CDATA[
SELECT COUNT(1)
  FROM CRAFT_AUTO_PEOPLE T
 WHERE T.UNIT_CODE = {0}
   AND T.AUDIT_CODE = {1}
   AND T.AUDIT_CODE1 = {2}
   AND T.APPROVE_CODE = {3}
   AND DECODE({4}, NULL, '1', T.APPROVE_CODE1) = NVL({4}, '1')
   AND T.AUTO_FLAG = '0'
   AND T.PK <> {5}
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.DeleteDesignUnit" desc="删除工艺评审人工审核">
        <![CDATA[
DELETE FROM CRAFT_ORD_DESIGN_UNIT T WHERE T.ORD_LN_PK = {0}
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.InsertDesignUnit" desc="新增工艺评审人工审核">
        <![CDATA[
INSERT INTO CRAFT_ORD_DESIGN_UNIT
  (ORD_LN_PK, AUDIT_CODE, AUDIT_CODE1, APPROVE_CODE, APPROVE_CODE1)
VALUES
  ({0}, {1}, {2}, {3}, {4})
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.UpdateCraftOrdAudit" desc="修改工艺评审审核人">
        <![CDATA[
UPDATE CRAFT_ORD_DESIGN T
   SET T.AUDIT_NAME    =
       (SELECT A.USERNAME FROM CORE_APP_USER A WHERE A.USERID = {0}),
       T.AUDIT_NAME1   =
       (SELECT A.USERNAME FROM CORE_APP_USER A WHERE A.USERID = {1}),
       T.APPROVAL_NAME =
       (SELECT A.USERNAME FROM CORE_APP_USER A WHERE A.USERID = {2}),
       T.APPROVAL_NAME1 =
       (SELECT A.USERNAME FROM CORE_APP_USER A WHERE A.USERID = {3}),
       T.AUDIT_TIME     = NULL,
       T.AUDIT_TIME1    = NULL,
       T.APPROVAL_TIME  = NULL,
       T.APPROVAL_TIME1 = NULL
 WHERE T.ORD_LN_PK = {4}
   AND T.CRAFT_SEQ = (SELECT MAX(B.CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN B
                       WHERE B.ORD_LN_PK = T.ORD_LN_PK)
        ]]>
    </query>
    <query id="CraftAutoPeopleDAL.getCraftOrdUnit" desc="获取工艺评审制定的审核人">
        <![CDATA[
SELECT * FROM CRAFT_ORD_DESIGN_UNIT T WHERE T.ORD_LN_PK = {0}
        ]]>
    </query>
    
    <query id="CraftAutoPeopleDAL.getMaxSeq" desc="获取工艺评审制定的审核人">
        <![CDATA[
SELECT MAX(T.MESSAGE_NO) MESSAGE_NO FROM APP_MESSAGE t WHERE T.MESSAGE_NO LIKE ? || '%'
        ]]>
    </query>
    
    <query id="CraftAutoPeopleDAL.InsertMessageInfo" desc="新增">
        <![CDATA[
 INSERT INTO APP_MESSAGE T(
	        T.MESSAGE_NO,
	       T.MESSAGE_TITLE,
	       T.MESSAGE_LEVEL_CODE,
	       T.MESSAGE_LEVEL_DESC,
	       T.MESSAGE_CLASS_CODE,
	       T.MESSAGE_CLASS_DESC,
	       T.RELEASE_TIME,
	       T.VALIDFLAG,
	       T.CREATE_TIME,
	       T.REFER_KEY,
	       T.APPROVAL_NODE,
	       T.WINDOW_KEY,
	       T.EVENT_KEY,
	       T.NEED_GROUP,
	       T.RELEASE_USERID,
	       T.RELEASE_NAME,
	       T.CREATE_USERID,
	       T.CREATE_NAME)
 VALUES( 
	       ?,?,?,?,?,
	       ?,SYSDATE,?,SYSDATE,?,
	       ?,?,?,?,
	       ?,?,?,?)
        ]]>
    </query>
    
<query id="CraftAutoPeopleDAL.InsertMessageUserInfo" desc="新增">
        <![CDATA[
 INSERT INTO APP_MESSAGE_USER T(
	        T.MESSAGE_NO,
	       T.TARGET_USERID,
	       T.TARGET_NAME,
	       T.VALIDFLAG,
	       T.USER_NODE
	       )
 VALUES(  ?,?,?,?,?)
        ]]>
    </query>
    
    <query id="CraftAutoPeopleDAL.DeleteMessageInfo" desc="新增">
        <![CDATA[
		 DELETE  APP_MESSAGE T
		 	WHERE T.REFER_KEY=?
        ]]>
    </query>
    
    <query id="CraftAutoPeopleDAL.DeleteMessageUserInfo" desc="新增">
        <![CDATA[
  		      DELETE  APP_MESSAGE_USER T
		 	WHERE T.MESSAGE_NO IN (SELECT MESSAGE_NO FROM APP_MESSAGE WHERE REFER_KEY=?)
        ]]>
    </query>
    
</queryMap>