批量恢复丢失关联关系的一种思路(以异常委外用料清单下推的委外领料单,现在两个单据关联性丢失了,上下查、全流程跟踪均无记录为例)

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

批量恢复丢失关联关系的一种思路(以异常委外用料清单下推的委外领料单,现在两个单据关联性丢失了,上下查、全流程跟踪均无记录为例)

问题描述:

在数据问题处理时,由于二开或其他原因导致大量关联关系丢失的处理,若一个个地重新插回去工作量大,因此本文尝试提供一个较为快捷的处理思路(以异常委外用料清单下推的委外领料单,现在两个单据关联性丢失了,上下查、全流程跟踪均无记录为例)

解决方案:

恢复关联关系思路整理:

0 前提:历史单据如在历史核算期间,则只能修复上下查关系,无法前台通过保存触发保存反写,反写字段需要另外做修复;

--以下最好现在测试环境执行,并以生成脚本的形式上线至正式环境

1 后台查出丢失关联关系的单据,并在上游单据的非重要文本字段(如备注)标记上 * 号

 

2 前台对标记的上游单据批量下推,并暂存生成的下游单据,产生新的关联关系

3.1 取数更新BF表[FTID]字段为原丢失关系的下有单据的明细表主键;更新主键[FROUTEID],可以newID()触发取数

 

SELECT  *

INTO    TEMP_T_BF_INSTANCEENTRY

FROM    ( SELECT     NEWID() AS FROUTEID

     --, TEntry.FROUTEID

                  , TEntry.FINSTANCEID

                  , TEntry.FLINEID

                  , TEntry.FSTABLENAME

                  , TEntry.FSID

                  , TEntry.FTTABLENAME

                  , SPMD_UPDATE.FENTRYID AS FTID

      --, TEntry.FTID

                  , TEntry.FFIRSTNODE

                  , TEntry.FCREATETIME

 

--UPDATE SPMDA_UPDATE SET SPMDA_UPDATE.FPMBILLNO = '@'

          FROM      T_BF_INSTANCE TInst

          INNER JOIN T_BF_INSTANCEENTRY TEntry ON TInst.FINSTANCEID = TEntry.FINSTANCEID

                                                  AND TEntry.FTTABLENAME = 'T_SUB_PICKMTRLDATA'

                                                  AND TEntry.FCREATETIME > '2019-04-24'

          INNER JOIN T_SUB_PICKMTRLDATA SPMD ON SPMD.FENTRYID = TEntry.FTID

          INNER JOIN T_SUB_PICKMTRL SPM ON SPMD.FID = SPM.FID

          INNER JOIN T_SUB_PICKMTRLDATA_LK SPMDK ON SPMDK.FENTRYID = SPMD.FENTRYID

          INNER JOIN T_SUB_PICKMTRLDATA SPMD_UPDATE ON SPMD.FSRCENTRYID = SPMD_UPDATE.FSRCENTRYID

                                                       AND SPMD.FSRCBILLTYPE = SPMD_UPDATE.FSRCBILLTYPE

          INNER JOIN T_SUB_PICKMTRLDATA_A SPMDA_UPDATE ON SPMDA_UPDATE.FENTRYID = SPMD_UPDATE.FENTRYID

                                                          AND SPMDA_UPDATE.FPMBILLNO = '*'

          INNER JOIN T_SUB_PICKMTRL SPM_UPDATE ON SPM_UPDATE.FID = SPMD_UPDATE.FID

                                                  AND SPM_UPDATE.FDOCUMENTSTATUS <> 'D'

--INNER JOIN T_BD_MATERIAL BM ON SPMD.FMATERIALID = BM.FMATERIALID

--INNER JOIN T_SUB_REQORDER SRO ON SPMD.FSUBREQID = SRO.FID

--INNER JOIN T_SUB_REQORDERENTRY SROE ON SRO.FID = SROE.FID AND SPMD.FSUBREQENTRYID = SROE.FENTRYID

--INNER JOIN T_SUB_REQORDERENTRY_L SROEL ON SROE.FENTRYID = SROEL.FENTRYID

          WHERE     1 = 1 ) A;

--ORDER BY SPM_UPDATE.FBILLNO ASC

--      , SPMD_UPDATE.FSEQ ASC;

 

3.2 取数更新LK表[FTID]字段为原丢失关系的下有单据的明细表主键;(修复反写的话)修复数量字段,根据反写规则引用的源单字段联查明细表取数,注意[%OLD]字段对应的是下推携带的数量(如申请数量,应发数量之类);更新主键[FLINKID],需要通过触发种子表取主键

 

SELECT  *

INTO    TEMP_T_SUB_PICKMTRLDATA_LK

FROM    (

--SELECT SPM_UPDATE.FBILLNO,SPMDA_UPDATE.FPMBILLNO,SPMD_UPDATE.FSEQ,TInst.*,TEntry.*,SPMD_UPDATE.FENTRYID

          SELECT    SPMD_UPDATE.FENTRYID AS FENTRYID

     -- , SPMDK.FENTRYID

                  , SPMDK.FLINKID

                  , SPMDK.FSTABLEID

                  , SPMDK.FSBILLID

                  , SPMDK.FSID

                  , SPMDK.FLNKTRACKERID

                  , SPMDK.FLNKSSTATE

                  , SPMDK.FLNKAMOUNT

                  , SPMDK.FFLOWID

                  , SPMDK.FFLOWLINEID

                  , SPMDK.FRULEID

                  , SPMDK.FSTABLENAME

     -- , SPMDK.FBASEACTUALQTY

                  , SPMD_UPDATE.FBASEACTUALQTY AS FBASEACTUALQTY

     -- , SPMDK.FBASEACTUALQTYOLD

                  , SPMD_UPDATE.FBASEAPPQTY AS FBASEAPPQTY

 

--UPDATE SPMDA_UPDATE SET SPMDA_UPDATE.FPMBILLNO = '@'

          FROM      T_BF_INSTANCE TInst

          INNER JOIN T_BF_INSTANCEENTRY TEntry ON TInst.FINSTANCEID = TEntry.FINSTANCEID

                                                  AND TEntry.FTTABLENAME = 'T_SUB_PICKMTRLDATA'

                                                  AND TEntry.FCREATETIME > '2019-04-24'

          INNER JOIN T_SUB_PICKMTRLDATA SPMD ON SPMD.FENTRYID = TEntry.FTID

          INNER JOIN T_SUB_PICKMTRL SPM ON SPMD.FID = SPM.FID

          INNER JOIN T_SUB_PICKMTRLDATA_LK SPMDK ON SPMDK.FENTRYID = SPMD.FENTRYID

          INNER JOIN T_SUB_PICKMTRLDATA SPMD_UPDATE ON SPMD.FSRCENTRYID = SPMD_UPDATE.FSRCENTRYID

                                                       AND SPMD.FSRCBILLTYPE = SPMD_UPDATE.FSRCBILLTYPE

          INNER JOIN T_SUB_PICKMTRLDATA_A SPMDA_UPDATE ON SPMDA_UPDATE.FENTRYID = SPMD_UPDATE.FENTRYID

                                                          AND SPMDA_UPDATE.FPMBILLNO = '*'

          INNER JOIN T_SUB_PICKMTRL SPM_UPDATE ON SPM_UPDATE.FID = SPMD_UPDATE.FID

                                                  AND SPM_UPDATE.FDOCUMENTSTATUS <> 'D'

--INNER JOIN T_BD_MATERIAL BM ON SPMD.FMATERIALID = BM.FMATERIALID

--INNER JOIN T_SUB_REQORDER SRO ON SPMD.FSUBREQID = SRO.FID

--INNER JOIN T_SUB_REQORDERENTRY SROE ON SRO.FID = SROE.FID AND SPMD.FSUBREQENTRYID = SROE.FENTRYID

--INNER JOIN T_SUB_REQORDERENTRY_L SROEL ON SROE.FENTRYID = SROEL.FENTRYID

          WHERE     1 = 1 ) A;

--ORDER BY SPM_UPDATE.FBILLNO ASC

--      , SPMD_UPDATE.FSEQ ASC;

 

4 将查询结果以生成脚本的形式生成脚本

--以下为正式环境的操作

5 执行脚本,插入至TEMP表,再将TEMP表数据关联更新至正式表

6 对恢复了关联关系的下游单据进行保存操作(如果反写未正常触发情况,可尝试先保存下上游单据,再来保存下游单据,亲测能触发反写)


批量恢复丢失关联关系的一种思路(以异常委外用料清单下推的委外领料单,现在两个单据关联性丢失了,上下查、全流程跟踪均无记录为例)

问题描述:在数据问题处理时,由于二开或其他原因导致大量关联关系丢失的处理,若一个个地重新插回去工作量大,因此本文尝试提供一个较为快...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息