CREATE OR REPLACE PROCEDURE "DYLTWZDSJ_CP_BA" (YWID IN VARCHAR2,
XKZBH IN VARCHAR2,
FLAG OUT VARCHAR2) IS
V_RAISE EXCEPTION;
V_YWLX CHAR(2); --业务类型
V_BAH VARCHAR2(50);
V_XXBID VARCHAR2(32);
V_GG_XKZ_YLYLQXPZ GG_XKZ_YLYLQXPZ%ROWTYPE;
V_BA_SQS XZXK_YLYLQX_BA_SQS%ROWTYPE;
BEGIN
SELECT T.YWLX INTO V_YWLX FROM XZXK_YLYLQX_BA_SQS T WHERE T.SQID = YWID;
--根据不同的业务类型做相应处理
IF (V_YWLX = 'A') THEN
--备案-----------------------------------------------
UPDATE GG_XKZ_YLYLQXPZ T
SET T.CZZT = 'V', T.GSBS = 'Y', T.PZZT = 'Y'
WHERE T.SQID = YWID;
--插入主表信息
INSERT INTO XZXK_YLYLQX_XX_QB
(XXBID,
CPLX,
CPID,
CPMC,
CPYWMC,
CPLDH,
CPLMC,
YJCPLB,
CPLXH,
EJCPLB,
JGTZ,
XHGG,
CPMS,
YQYT,
CPYXQ,
QYID,
QYMC,
QYYWMC,
ZCDZ,
ZCDSZSF,
ZCDSZQX,
ZCDYWMC,
SCDZ,
BARSZD,
ZZJGDM,
LXR,
LXDH,
CZ,
YB,
DZXX,
QTXYSMDWT,
INSTNUM,
LASTDATE,
DATEXC)
SELECT T.SQID,
T.CPLX,
T.CPID,
T.CPMC,
T.CPYWMC,
T.CPLDH,
T.CPLMC,
T.YJCPLB,
T.CPLXH,
T.EJCPLB,
T.JGTZ,
T.XHGG,
T.CPMS,
T.YQYT,
T.CPYXQ,
T.QYID,
T.QYMC,
T.QYYWMC,
T.ZCDZ,
T.ZCDSZSF,
T.ZCDSZQX,
T.ZCDYWMC,
T.SCDZ,
T.BARSZD,
T.ZZJGDM,
T.LXR,
T.LXDH,
T.CZ,
T.YB,
T.DZXX,
T.QTXYSMDWT,
F_GETSLBS AS INSTNUM,
SYSDATE AS LASTDATE,
'11' AS DATEXC
FROM XZXK_YLYLQX_BA_SQS T
WHERE T.SQID = YWID;
--插入规格/型号表信息
INSERT INTO XZXK_YLYLQX_XX_GGXH
(BZJ, XXBID, CPID, CPMC, CPXH, INSTNUM, LASTDATE, DATEXC)
SELECT T .BZJ,
T .SQID AS XXBID,
T .CPID,
T .CPMC,
T .CPXH,
F_GETSLBS AS INSTNUM,
SYSDATE AS LASTDATE,
'11' AS DATEXC
FROM XZXK_YLYLQX_BA_GGXH T
WHERE T.SQID = YWID;
--插入生产地址
INSERT INTO XZXK_YLYLQX_XX_SCDZ
(BZJ,
XXBID,
JTDZ,
SZSF,
SZQX,
SZJD,
LXDH,
YB,
INSTNUM,
LASTDATE,
DATEXC)
SELECT T .BZJ,
T .SQID AS XXBID,
T .JTDZ,
T .SZSF,
T .SZQX,
T .SZJD,
T .LXDH,
T .YB,
F_GETSLBS AS INSTNUM,
SYSDATE AS LASTDATE,
'11' AS DATEXC
FROM XZXK_YLYLQX_BA_SCDZ T
WHERE T.SQID = YWID;
--通过凭证表更新信息全表
SELECT T.*
INTO V_GG_XKZ_YLYLQXPZ
FROM GG_XKZ_YLYLQXPZ T
WHERE T.SQID = YWID;
UPDATE XZXK_YLYLQX_XX_QB T
SET T .BAH = V_GG_XKZ_YLYLQXPZ.BAH,
T .QYID = V_GG_XKZ_YLYLQXPZ.BARID,
T .QYMC = V_GG_XKZ_YLYLQXPZ.BARMC,
T .ZZJGDM = V_GG_XKZ_YLYLQXPZ.ZZJGDM,
T .ZCDZ = V_GG_XKZ_YLYLQXPZ.ZCDZ,
T .SCDZ = V_GG_XKZ_YLYLQXPZ.SCDZ,
T .CPMC = V_GG_XKZ_YLYLQXPZ.CPMC,
T .XHGG = V_GG_XKZ_YLYLQXPZ.BZGG,
T .CPMS = V_GG_XKZ_YLYLQXPZ.CPMS,
T .YQYT = V_GG_XKZ_YLYLQXPZ.YQYT,
T .CPYXQ = V_GG_XKZ_YLYLQXPZ.CPYXQ,
T .BZ = V_GG_XKZ_YLYLQXPZ.BZ,
T .BADWBH = V_GG_XKZ_YLYLQXPZ.BADWBH,
T .BADW = V_GG_XKZ_YLYLQXPZ.BADW,
T .BARQ = V_GG_XKZ_YLYLQXPZ.BARQ,
T.PZZT = V_GG_XKZ_YLYLQXPZ.PZZT,
T .INSTNUM = F_GETSLBS,
T .LASTDATE = SYSDATE,
T .DATEXC = '11'
WHERE T.XXBID = YWID;
ELSIF (V_YWLX = 'G') THEN
--变更-----------------------------------------------
SELECT BAH INTO V_BAH FROM XZXK_YLYLQX_BA_SQS WHERE SQID = YWID;
SELECT XXBID INTO V_XXBID FROM XZXK_YLYLQX_XX_QB WHERE BAH = V_BAH;
SELECT * INTO V_BA_SQS FROM XZXK_YLYLQX_BA_SQS WHERE SQID = YWID;
SELECT * INTO V_GG_XKZ_YLYLQXPZ FROM GG_XKZ_YLYLQXPZ WHERE SQID = YWID;
--有效一条状态设置为无效
UPDATE GG_XKZ_YLYLQXPZ T
SET T.CZZT = 'I',
T.PZZT = 'N',
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.CZZT = 'V'
AND T.PZZT = 'Y'
AND T.BAH = V_BAH;
--最新一条设置为有效
UPDATE GG_XKZ_YLYLQXPZ T
SET T.PZZT = 'Y',
T.CZZT = 'V',
T.DYBS = '000',
T.GSBS = 'Y',
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.BAH = V_BAH
AND T.SQID = YWID
AND T.CZZT = 'T';
--
UPDATE XZXK_YLYLQX_XX_QB
SET CPLX = V_BA_SQS.CPLX,
CPID = V_BA_SQS.CPID,
CPMC = V_BA_SQS.CPMC,
CPYWMC = V_BA_SQS.CPYWMC,
CPLDH = V_BA_SQS.CPLDH,
CPLMC = V_BA_SQS.CPLMC,
YJCPLB = V_BA_SQS.YJCPLB,
CPLXH = V_BA_SQS.CPLXH,
EJCPLB = V_BA_SQS.EJCPLB,
JGTZ = V_BA_SQS.JGTZ,
XHGG = V_BA_SQS.XHGG,
CPMS = V_BA_SQS.CPMS,
YQYT = V_BA_SQS.YQYT,
CPYXQ = V_BA_SQS.CPYXQ,
QYID = V_BA_SQS.QYID,
QYMC = V_BA_SQS.QYMC,
QYYWMC = V_BA_SQS.QYYWMC,
ZCDZ = V_BA_SQS.ZCDZ,
ZCDSZSF = V_BA_SQS.ZCDSZSF,
ZCDSZQX = V_BA_SQS.ZCDSZQX,
ZCDYWMC = V_BA_SQS.ZCDYWMC,
SCDZ = V_BA_SQS.SCDZ,
BARSZD = V_BA_SQS.BARSZD,
ZZJGDM = V_BA_SQS.ZZJGDM,
LXR = V_BA_SQS.LXR,
LXDH = V_BA_SQS.LXDH,
CZ = V_BA_SQS.CZ,
YB = V_BA_SQS.YB,
DZXX = V_BA_SQS.DZXX,
QTXYSMDWT = V_BA_SQS.QTXYSMDWT,
BAH = V_BA_SQS.BAH,
BZ = V_BA_SQS.BZ,
BADWBH = V_BA_SQS.BADWBH,
BADW = V_BA_SQS.BADW,
BARQ = V_BA_SQS.BARQ,
JDJC = '',
BJRY = '',
BJRQ = '',
INSTNUM = F_GETSLBS,
LASTDATE = SYSDATE,
DATEXC = '11'
WHERE XXBID = V_XXBID;
INSERT INTO PUB_TABLE_DATA_DELEXC
(ID,
TABLENAME,
TABLEPKNAME,
TABLEPK,
DELFLAG,
INSTNUM,
LASTDATE,
DATEXC)
SELECT SYS_GUID(),
'XZXK_YLYLQX_XX_GGXH',
'BZJ',
BZJ AS TABLEPK,
'N',
F_GETSLBS(),
SYSDATE,
'11'
FROM XZXK_YLYLQX_XX_GGXH
WHERE XXBID = V_XXBID;
DELETE FROM XZXK_YLYLQX_XX_GGXH WHERE XXBID = V_XXBID;
INSERT INTO PUB_TABLE_DATA_DELEXC
(ID,
TABLENAME,
TABLEPKNAME,
TABLEPK,
DELFLAG,
INSTNUM,
LASTDATE,
DATEXC)
SELECT SYS_GUID(),
'XZXK_YLYLQX_XX_BGQK',
'BZJ',
BZJ AS TABLEPK,
'N',
F_GETSLBS(),
SYSDATE,
'11'
FROM XZXK_YLYLQX_XX_BGQK
WHERE XXBID = V_XXBID;
DELETE FROM XZXK_YLYLQX_XX_BGQK WHERE XXBID = V_XXBID;
INSERT INTO PUB_TABLE_DATA_DELEXC
(ID,
TABLENAME,
TABLEPKNAME,
TABLEPK,
DELFLAG,
INSTNUM,
LASTDATE,
DATEXC)
SELECT SYS_GUID(),
'XZXK_YLYLQX_XX_SCDZ',
'BZJ',
BZJ AS TABLEPK,
'N',
F_GETSLBS(),
SYSDATE,
'11'
FROM XZXK_YLYLQX_XX_SCDZ
WHERE XXBID = V_XXBID;
DELETE FROM XZXK_YLYLQX_XX_SCDZ WHERE XXBID = V_XXBID;
--插入规格/型号表信息
INSERT INTO XZXK_YLYLQX_XX_GGXH
(BZJ, XXBID, CPID, CPMC, CPXH, INSTNUM, LASTDATE, DATEXC)
SELECT T .BZJ,
V_XXBID,
T .CPID,
T .CPMC,
T .CPXH,
F_GETSLBS AS INSTNUM,
SYSDATE AS LASTDATE,
'11' AS DATEXC
FROM XZXK_YLYLQX_BA_GGXH T
WHERE T.SQID = YWID;
--插入生产地址
INSERT INTO XZXK_YLYLQX_XX_SCDZ
(BZJ,
XXBID,
JTDZ,
SZSF,
SZQX,
SZJD,
LXDH,
YB,
INSTNUM,
LASTDATE,
DATEXC)
SELECT T .BZJ,
V_XXBID,
T .JTDZ,
T .SZSF,
T .SZQX,
T .SZJD,
T .LXDH,
T .YB,
F_GETSLBS AS INSTNUM,
SYSDATE AS LASTDATE,
'11' AS DATEXC
FROM XZXK_YLYLQX_BA_SCDZ T
WHERE T.SQID = YWID;
--变更情况
INSERT INTO XZXK_YLYLQX_XX_BGQK
(BZJ, XXBID, SXH, BAH, BGNR, INSTNUM, LASTDATE, DATEXC)
SELECT BZJ, V_XXBID, SXH, BAH, BGNR, F_GETSLBS, SYSDATE, '11'
FROM GG_XKZ_YLYLQXPZ_BGQK
WHERE BAH = V_BAH
AND PZZJ = V_GG_XKZ_YLYLQXPZ.PZZJ;
--凭证更新到信息表
UPDATE XZXK_YLYLQX_XX_QB
SET BAH = V_GG_XKZ_YLYLQXPZ.BAH,
ZZJGDM = V_GG_XKZ_YLYLQXPZ.ZZJGDM,
ZCDZ = V_GG_XKZ_YLYLQXPZ.ZCDZ,
SCDZ = V_GG_XKZ_YLYLQXPZ.SCDZ,
CPMC = V_GG_XKZ_YLYLQXPZ.CPMC,
CPMS = V_GG_XKZ_YLYLQXPZ.CPMS,
YQYT = V_GG_XKZ_YLYLQXPZ.YQYT,
CPYXQ = V_GG_XKZ_YLYLQXPZ.CPYXQ,
BZ = V_GG_XKZ_YLYLQXPZ.BZ,
BADWBH = V_GG_XKZ_YLYLQXPZ.BADWBH,
BADW = V_GG_XKZ_YLYLQXPZ.BADW,
BARQ = V_GG_XKZ_YLYLQXPZ.BARQ,
ZXRQ = V_GG_XKZ_YLYLQXPZ.ZXRQ,
ZXDWBH = V_GG_XKZ_YLYLQXPZ.ZXDWBH,
ZXDW = V_GG_XKZ_YLYLQXPZ.ZXDW,
JDJC = V_GG_XKZ_YLYLQXPZ.JDJC,
BJRY = V_GG_XKZ_YLYLQXPZ.BJRY,
BJRQ = V_GG_XKZ_YLYLQXPZ.BJRQ,
INSTNUM = F_GETSLBS,
LASTDATE = SYSDATE,
DATEXC = '11'
WHERE XXBID = V_XXBID;
ELSIF (V_YWLX = 'Z') THEN
--补证-----------------------------------------------
SELECT T.BAH INTO V_BAH FROM XZXK_YLYLQX_BA_SQS T WHERE T.SQID = YWID;
--有效一条状态设置为无效
UPDATE GG_XKZ_YLYLQXPZ T
SET T.CZZT = 'I',
T.PZZT = 'N',
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.CZZT = 'V'
AND T.PZZT = 'Y'
AND T.BAH = V_BAH;
--最新一条设置为有效
UPDATE GG_XKZ_YLYLQXPZ T
SET T.PZZT = 'Y',
T.CZZT = 'V',
T.DYBS = '000',
T.GSBS = 'Y',
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.BAH = V_BAH
AND T.SQID = YWID
AND T.CZZT = 'T';
--更新信息全表
SELECT T.*
INTO V_GG_XKZ_YLYLQXPZ
FROM GG_XKZ_YLYLQXPZ T
WHERE T.SQID = YWID;
UPDATE XZXK_YLYLQX_XX_QB T
SET T.BZ = V_GG_XKZ_YLYLQXPZ.BZ,
T.JDJC = V_GG_XKZ_YLYLQXPZ.JDJC,
T.BJRY = V_GG_XKZ_YLYLQXPZ.BJRY,
T.BJRQ = V_GG_XKZ_YLYLQXPZ.BJRQ,
T.PZZT = V_GG_XKZ_YLYLQXPZ.PZZT,
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.BAH = V_BAH;
ELSIF (V_YWLX = 'X') THEN
--注销-----------------------------------------------
SELECT T.BAH INTO V_BAH FROM XZXK_YLYLQX_BA_SQS T WHERE T.SQID = YWID;
--有效一条状态设置为无效
UPDATE GG_XKZ_YLYLQXPZ T
SET T.CZZT = 'I',
T.PZZT = 'N',
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.CZZT = 'V'
AND T.BAH = V_BAH;
--最新一条设置为有效
UPDATE GG_XKZ_YLYLQXPZ T
SET T.CZZT = 'V',
T.DYBS = '000',
T.GSBS = 'Y',
T.PZZT = 'N',
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.BAH = V_BAH
AND T.SQID = YWID
AND T.CZZT = 'T';
--更新信息全表
SELECT T.*
INTO V_GG_XKZ_YLYLQXPZ
FROM GG_XKZ_YLYLQXPZ T
WHERE T.SQID = YWID;
UPDATE XZXK_YLYLQX_XX_QB T
SET T.BZ = V_GG_XKZ_YLYLQXPZ.BZ,
T.ZXDWBH = V_GG_XKZ_YLYLQXPZ.ZXDWBH,
T.ZXDW = V_GG_XKZ_YLYLQXPZ.ZXDW,
T.ZXRQ = V_GG_XKZ_YLYLQXPZ.ZXRQ,
T.JDJC = V_GG_XKZ_YLYLQXPZ.JDJC,
T.BJRY = V_GG_XKZ_YLYLQXPZ.BJRY,
T.BJRQ = V_GG_XKZ_YLYLQXPZ.BJRQ,
T.PZZT = V_GG_XKZ_YLYLQXPZ.PZZT,
T.INSTNUM = F_GETSLBS,
T.LASTDATE = SYSDATE,
T.DATEXC = '11'
WHERE T.BAH = V_BAH;
END IF;
FLAG := 'Y';
COMMIT;
EXCEPTION
WHEN V_RAISE THEN
FLAG := 'N';
ROLLBACK;
WHEN NO_DATA_FOUND THEN
FLAG := 'N';
ROLLBACK;
END DYLTWZDSJ_CP_BA;