<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="计划排产队列表">
    <query id="PlaSaleOrdProcDAL.query" desc="查询排产队列表">
		<![CDATA[
SELECT T.ORD_LN_DLY_PK,
       T.PLN_DIVIDE_ID,
       T.ORDER_SOURCE,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.R_NUM_ID,
       A.PSC_DESC PSC,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T.MSC,
       T.INDEX_SEQ,
       T.PROCESS_SEQ,
       T.BOM,
       T.GRADECODE_ALL,
       T.GRADECODE,
       DECODE(T.G_IS_OK, '0', '否', '1', '是', '/') G_IS_OK,
       T.GROUP_JGX,
       DECODE(T.F_IS_OK, '0', '否', '1', '是', '/') F_IS_OK,
       T.GROUP_RCL,
       T.GROUP_ROLL_ALL,
       T.GROUP_ROLL,
       T.BJ_TYPE,
       T.E_IN_MATERIAL_NO,
       T.E_IN_MATERIAL_DESC,
       T.DIMATER_YLG,
       T.HEIGHT_YLG,
       T.MATERIAL_NO,
       T.MATERIAL_DESC,
       T.STUFF_PROPERTY,
       DECODE(T.GRADECODE_IS_OK, '0', '否', '1', '是', '/') GRADECODE_IS_OK,
       DECODE(T.D_IS_OK, '0', '否', '1', '是', '/') D_IS_OK,
       DECODE(T.E_IS_OK, '0', '否', '1', '是', '/') E_IS_OK,
       T.WEIGHT_PER_M,
       T.PLAN_WT_D,
       T.PLAN_NUM_D,
       T.FINISH_WT,
       T.IF_CHANGE,
       T.PLAN_WT_BEGIN,
       T.PLAN_NUM_BEGIN,
       DECODE(T.PLANSTATUS,
              '1',
              '计划',
              '2',
              '已下发',
              '3',
              '生产中',
              '4',
              '生产完成',
              '5',
              '关闭',
              '6',
              '取消') PLANSTATUS,
       DECODE(T.IF_ALLOW_ISSUE, '1', '是', '0', '否') IF_ALLOW_ISSUE,
       TO_CHAR(T.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
       T.ISSUED_MAN,
       T.HEIGHT_NK_MIN,
       T.HEIGHT_NK_MAX,
       T.ORDER_QTY_D,
       T.ORDER_UNIT,
       T.AIM_LEN_ROLL,
       T.AIM_LEN_END,
       T.PLAN_P_MAIN,
       T.PLAN_TOT_LEN_D,
       T.TOT_LEN_ONE_P,
       T.CUT_NUM_P,
       T.CRAFT_SEQ,
       T.CRAFT_NO_V,
       T.AIM_WALLTHICK,
       T.ROLL_LENGTH,
       DECODE(T.CRAFT_RENEW_ST, '0', '无更新', '1', '待替换', '2', '已替换') CRAFT_RENEW_ST,
       T.CRAFT_NO_NEW,
       T.CRAFT_NO_V_NEW
  FROM PLN_SALEORD_PROC T
  LEFT JOIN COM_PSC A
    ON A.PSC = T.PSC
 WHERE T.CRAFT_FILE_NO = '#CRAFT_NO#'
   AND T.CRAFT_NO_V = '#CRAFT_NO_V#'
   AND T.PLANSTATUS IN ('2', '3')
		]]>
	</query>
	
    <query id="PlaSaleOrdProcDAL.queryCount" desc="查询排产队列表">
		<![CDATA[
SELECT COUNT(1) COUNT
  FROM PLN_SALEORD_PROC T
 WHERE T.CRAFT_FILE_NO = '#CRAFT_NO#'
   AND T.CRAFT_NO_V = '#CRAFT_NO_V#'
		]]>
	</query>
	
    <query id="PlaSaleOrdProcDAL.queryPlaProcByPk" desc="通过主键查询排产队列表">
		<![CDATA[
SELECT *
  FROM PLN_SALEORD_PROC T
 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
    <query id="PlaSaleOrdProcDAL.upgradeCraft" desc="升级工艺文件">
		<![CDATA[
DECLARE
BEGIN
  UPDATE PLN_SALEORD_PROC T
     SET T.CRAFT_NO_NEW   = '#CRAFT_NO_NEW#',
         T.CRAFT_NO_V_NEW = '#CRAFT_NO_V_NEW#',
         T.CRAFT_RENEW_ST = '1'
   WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
     AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#';

  UPDATE PLN_SALEORD T
     SET T.CRAFT_FILE_NO = '#CRAFT_NO_NEW#', T.CRAFT_NO_V = '#CRAFT_NO_V_NEW#'
   WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#';
END;
		]]>
	</query>
	
	<query id="PlaSaleOrdProcDAL.IsIssued" desc="是否已下发">
		<![CDATA[
SELECT 1
     FROM PLN_SALEORD_PROC T
    WHERE T.CRAFT_FILE_NO = '#CRAFT_NO#'
      AND T.CRAFT_NO_V = '#CRAFT_NO_V#'
      AND T.PLANSTATUS IN ('2', '3', '4', '5', '8', '9')
		]]>
	</query>
</queryMap>