ALTER proc [fin].[p_invc_files_save_invc_data]
(
@tbl diytbl300 readonly ,
@user_name nvarchar(50) = 'InvoiceBatch'
)
as
set nocount on
select
f.f0 sys_guid ,
isnull(f.f1,'') 发票分类 ,
isnull(f.f2,'') 发票科室 ,
isnull(f.f3,'') 发票担当 ,
isnull(f.f4,'') 发票号 ,
isnull(f.f5,'') 发票代码 ,
isnull(f.f6,'') 发票号码 ,
isnull(f.f7,'') 数电票号码 ,
isnull(f.f8,'') 销方识别号 ,
isnull(f.f9,'') 销方名称 ,
isnull(f.f0,'') 购方识别号 ,
isnull(f.f11,'') 购买方名称 ,
isnull(f.f12,'') 开票日期 ,
case when isnull(f.f13,'') in ( '','.','-' ) or isnumeric(f.f13) = 0 then 0 else cast(f.f13 as decimal(18,2)) end 金额 ,
case when isnull(f.f14,'') in ( '','.','-' ) or isnumeric(f.f14) = 0 then 0 else cast(f.f14 as decimal(18,2)) end 税额 ,
case when isnull(f.f15,'') in ( '','.','-' ) or isnumeric(f.f15) = 0 then 0 else cast(f.f15 as decimal(18,2)) end 价税合计 ,
isnull(f16,'') 电子附件 ,
isnull(f.f17,'') 发票来源 ,
isnull(f.f18,'') 发票票种 ,
isnull(f.f19,'') 发票状态 ,
isnull(f.f20,'') 是否正数发票 ,
isnull(f.f21,'') 发票风险等级 ,
isnull(f.f22,'') 开票人 ,
isnull(f.f23,'') 备注 ,
isnull(f.f24,'') rem_01 ,
isnull(f.f25,'') rem_02 ,
isnull(f.f26,'') rem_03 into #t1
from @tbl f
inner join fin.发票基础信息 d on d.guid_id = f.f0
and d.发票来源 like '%手工%'
where len(isnull(f.f4,'')) >= 4
select * from #t1
where 1 = 2
if @@rowcount = 0
begin
;
with a as (
select f.sys_guid , max(f1.id) rel_id
from #t1 f
inner join fin.发票基础信息 f1 on f1.发票号码 = f.发票号码
--and f1.发票代码 = f.发票代码
where f1.发票来源 not like '%手工%'
group by f.sys_guid
)
update t
set 数电票号码 = f1. 数电票号码 ,
发票号码 = f1. 发票号码 ,
发票代码 = f1. 发票代码 ,
销方识别号 = f1. 销方识别号 ,
销方名称 = f1. 销方名称 ,
购方识别号 = f1. 购方识别号 ,
购买方名称 = f1. 购买方名称 ,
开票日期 = f1. 开票日期 ,
金额 = f1. 金额 ,
税额 = f1. 税额 ,
价税合计 = f1. 价税合计 ,
发票票种 = case when t.发票票种 = '' then f1.发票票种 else t.发票票种 end ,
发票状态 = f1. 发票状态 ,
是否正数发票 = f1. 是否正数发票 ,
发票风险等级 = f1. 发票风险等级 ,
开票人 = f1. 开票人 ,
备注 = f1. 备注
from #t1 t
inner join a on a.sys_guid = t.sys_guid
inner join fin.发票基础信息 f1 on f1.id = a.rel_id
update t
set 数电票号码 = f1. 数电票号码 ,
发票号码 = f1. 发票号码 ,
发票代码 = f1. 发票代码 ,
销方识别号 = f1. 销方识别号 ,
销方名称 = f1. 销方名称 ,
购方识别号 = f1. 购方识别号 ,
购买方名称 = f1. 购买方名称 ,
开票日期 = f1. 开票日期 ,
金额 = f1. 金额 ,
税额 = f1. 税额 ,
价税合计 = f1. 价税合计 ,
发票票种 = case when t.发票票种 = '' then f1.发票票种 else t.发票票种 end ,
发票状态 = f1. 发票状态 ,
是否正数发票 = f1. 是否正数发票 ,
发票风险等级 = f1. 发票风险等级 ,
开票人 = f1. 开票人 ,
备注 = f1. 备注 ,
发票分类 = f1.发票分类 ,
发票科室 = f1.发票科室 ,
发票担当 = f1.发票担当 ,
rem_01 = f1.rem_01 ,
rem_02 = f1.rem_02 ,
rem_03 = f1.rem_03 ,
mod_user = @user_name ,
mod_time = getdate()
from #t1 f1
inner join fin.发票基础信息 t on f1.sys_guid = t.rel_id
end
drop table #t1
USE [pettycash]
GO
/****** Object: StoredProcedure [dbo].[p_user_mapping_sav] Script Date: 2025/8/20 15:18:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[p_user_mapping_sav]
(
@user_name1 nvarchar(50) = '' ,
@tb1 diytbl readonly ,
@tbDelete diytbl readonly
)
AS
BEGIN
-- 临时表 --
select
ISNULL(f0, '') guid_id , -- sys_guid --
ISNULL(f1, '') soft_name , -- 软件名称 --
ISNULL(f2, '') host_user , -- 主机名 --
ISNULL(f3, '') card_name , -- 用户名 --
ISNULL(f4, '') user_name , -- 用户姓名 --
ISNULL(f5, '') version_id , -- 版本号 --
case
--when ISNULL(f6, '') = ''then convert(nvarchar(50), getdate(), 120) -- 格式:2025-08-19 08:43:56
when ISNULL(f6, '') = ''then convert(nvarchar(50), getdate(), 112) -- 启用日期 格式:20250819 --
else ISNULL(f6, '')
end as begin_date ,
case
when ISNULL(f7, '') = ''then '20991231' -- 停用日期 --
else ISNULL(f7, '')
end as end_date ,
ISNULL(f8, '') rem_01 , -- 备注01 --
ISNULL(f9, '') rem_02 , -- 备注02 --
ISNULL(f10, '') rem_03 , -- 备注03 --
GETDATE() ins_time , -- 录入时间 --
@user_name1 ins_user , -- 录入人 --
GETDATE() upd_time , -- 更新时间 --
@user_name1 upd_user , -- 更新人 --
ISNULL(f11, '') is_delete -- 删除标识 --
into #TT
from @tb1
-- 处理删除逻辑 --
if exists (select 1 from @tbDelete)
begin
delete u
from user_mapping u
inner join @tbDelete d on u.guid_id = d.f0
where d.f0 is not null and d.f0 <> ''
end
-- 数据验证 --
if exists(
select 1 from #TT
where soft_name <> ''
and host_user <> ''
and card_name <> ''
and user_name <> ''
)
begin
-- 插入新纪录 --
insert into user_mapping
(
soft_name ,
host_user ,
card_name ,
user_name ,
version_id ,
begin_date ,
end_date ,
rem_01 ,
rem_02 ,
rem_03 ,
ins_time ,
ins_user ,
upd_time ,
upd_user
)
select
T.soft_name ,
T.host_user ,
T.card_name ,
T.user_name ,
T.version_id ,
T.begin_date ,
T.end_date ,
T.rem_01 ,
T.rem_02 ,
T.rem_03 ,
T.ins_time ,
T.ins_user ,
T.upd_time ,
T.upd_user
from #TT T
left join user_mapping u on u.guid_id = T.guid_id
where u.guid_id is null or T.guid_id = ''
-- 更新记录 --
update u
set
soft_name = T.soft_name ,
host_user = T.host_user ,
card_name = T.card_name ,
user_name = T.user_name ,
version_id = T.version_id ,
begin_date = T.begin_date ,
end_date = T.end_date ,
rem_01 = T.rem_01 ,
rem_02 = T.rem_02 ,
rem_03 = T.rem_03 ,
upd_time = T.upd_time ,
upd_user = T.upd_user
from #TT T
inner join user_mapping u on u.guid_id = T.guid_id
end
drop table #TT
END
fin.发票基础信息表的mod_user与ins_user默认值为host_name(),现在要求将mod_user与ins_user更改为与user_mapping表的host_name列匹配相同的对应的user_mapping表的user_name值
最新发布